logicgraph_parser.rb revision 6461858b2085dd222cd62e3e5dbb3d92f4cc4225
# This module parses the logic graph outputed by Hets.
#
# It is a use-once-and-discard code and for this reason it does not have
# regression tests.
#
# Author:: Daniel Couto Vale (mailto:danielvale@uni-bremen.de)
# Copyright:: Copyright (c) 2013 Bremen University, SFBTR8
# License:: Distributed as a part of Ontohub.
#
# Parses the given string and executes the callback for each symbol
print "parse\n"
# Create a new parser
# Feed the parser some XML
end
# Listener for the SAX Parser
ROOT = 'LogicGraph'
LOGIC = 'logic'
COMORPHISM = 'comorphism'
SOURCE_SUBLOGIC = 'sourceSublogic'
TARGET_SUBLOGIC = 'targetSublogic'
DESCRIPTION = 'Description'
SERIALIZATION = 'Serialization'
PROVER = 'Prover'
CONSERVATIVITY = 'ConservativityChecker'
CONSISTENCY = 'ConsistencyChecker'
# the callback function is called for each Symbol tag
print "init\n"
@path = []
@current_logic = nil
end
# Makes a logic mapping singleton for a given key
end
end
# Make a logic singleton for a given key
end
end
# Make a language singleton for a given key
end
end
end
end
end
# Parses the element opening tag
print "====>start "
@path << name
case name
when ROOT
print "graph"
callback(:root, Hash[*[attributes]])
when LOGIC
print "logic "
hash = Hash[*[attributes]]
@current_logic = make_logic(hash['name'])
@current_language = make_language(hash['name'])
@current_support = make_support(hash['name'], hash['name'])
callback(:logic, @current_logic)
callback(:language, @current_language)
callback(:support, @current_support)
when COMORPHISM
hash = Hash[*[attributes]]
@current_comorphism = make_mapping(hash['name'])
if @path[-2] == SOURCE_SUBLOGIC
print "source sublogic comorphism"
@current_comorphism.source = @current_source_sublogic
elsif @path[-2] == TARGET_SUBLOGIC
print "target sublogic comorphism"
@current_comorphism.target = @current_target_sublogic
else
# Get attributes
if hash['is_weakly_amalgamable'] == 'TRUE'
@current_comorphism.exactness = LogicMapping::EXACTNESSES[2]
else
@current_comorphism.exactness = LogicMapping::EXACTNESSES[0]
end
if hash['has_model_expansion'] == 'TRUE'
@current_comorphism.faithfulness = LogicMapping::FAITHFULNESSES[2]
else
@current_comorphism.faithfulness = LogicMapping::FAITHFULNESSES[0]
end
print "comorphism"
end
when SOURCE_SUBLOGIC
print "source sublogic"
hash = Hash[*[attributes]]
@current_source_sublogic = make_logic(hash['name'])
callback(:logic, @current_source_sublogic)
when TARGET_SUBLOGIC
print "target sublogic"
hash = Hash[*[attributes]]
@current_target_sublogic = make_logic(hash['name'])
callback(:logic, @current_target_sublogic)
when DESCRIPTION
print "description"
when SERIALIZATION
hash = Hash[*[attributes]]
print "serialization"
name = hash['name']
serialization = @current_language.serializations.create
serialization.name = name
serialization.extension = name
serialization.mimetype = name
@current_language.serializations << serialization
when PROVER
print "prover"
when CONSERVATIVITY
print "conservativity checker"
when CONSISTENCY
print "consistency checker"
end
print ".\n"
end
# Parses the element closing tag
def end_element(name)
print "======>end "
@path.pop
case name
when ROOT
print "graph\n"
when LOGIC
print "logic\n"
callback(:logic, @current_logic)
callback(:language, @current_language)
callback(:support, @current_support)
@current_logic = nil
@current_language = nil
@current_support = nil
when COMORPHISM
if @path[-1] == SOURCE_SUBLOGIC
print "source sublogic comorphism\n"
elsif @path[-1] == TARGET_SUBLOGIC
print "target sublogic comorphism\n"
else
callback(:logic_mapping, @current_comorphism)
print "comorphism\n"
end
@current_comorphism = nil
when SOURCE_SUBLOGIC
print "source sublogic\n"
@current_axiom = nil
when TARGET_SUBLOGIC
print "target sublogic\n"
@current_link = nil
when DESCRIPTION
print "description\n"
when SERIALIZATION
print "serialization\n"
when PROVER
print "prover\n"
when CONSERVATIVITY
print "conservativity checker\n"
when CONSISTENCY
print "consistency checker\n"
end
end
# Parses a text node
def characters(text)
case @path.last
when DESCRIPTION
@current_logic.description = text if @current_logic
@current_language.description = text if @current_language
end
#case @path.last
# when SYMBOL
# @current_symbol['text'] << text if @current_symbol
# when TEXT
# @current_axiom['text'] << text if @current_axiom
# when TYPE # there is no other use of TYPE in this code
# @current_link['type'] = text if @current_link
#end
end
# error handler for parsing problems
# this exception is not being used so far
def error(string)
print "err\n"
#raise ParseException, 'cannot parse: ' + string
end
private
def callback(name, args)
print "::callback\n"
block = @callbacks[name]
block.call(args) if block
end
end
end