node_evaluator.rb revision 2a321cbae5b2d4957f2a1a36946087bdf78c5335
76b43e4417bab52e913da39b5f5bc2a130d3f149Timo Sirainenmodule Hets
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen module DG
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen class NodeEvaluator < ConcurrentEvaluator
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen include NodeEvaluationHelper
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen attr_accessor :current_element
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen attr_accessor :internal_iri
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen register :all, :end, to: :all_end
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen register :root, :start, to: :dgraph
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen register :ontology, :start, to: :ontology_start
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen register :ontology, :end, to: :ontology_end
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen register :import, :start, to: :import
f16c114c20bbd7d292d93415d1e56c8dd6abd3e7Timo Sirainen register :symbol, :end, to: :symbol
f16c114c20bbd7d292d93415d1e56c8dd6abd3e7Timo Sirainen register :axiom, :end, to: :axiom
f16c114c20bbd7d292d93415d1e56c8dd6abd3e7Timo Sirainen register :imported_axiom, :end, to: :imported_axiom
f16c114c20bbd7d292d93415d1e56c8dd6abd3e7Timo Sirainen register :theorem, :end, to: :theorem
f16c114c20bbd7d292d93415d1e56c8dd6abd3e7Timo Sirainen register :mapping, :end, to: :mapping
f16c114c20bbd7d292d93415d1e56c8dd6abd3e7Timo Sirainen
f16c114c20bbd7d292d93415d1e56c8dd6abd3e7Timo Sirainen def dgraph(current_element)
f16c114c20bbd7d292d93415d1e56c8dd6abd3e7Timo Sirainen importer.dgnode_count = current_element['dgnodes'].to_i
f16c114c20bbd7d292d93415d1e56c8dd6abd3e7Timo Sirainen end
f16c114c20bbd7d292d93415d1e56c8dd6abd3e7Timo Sirainen
f16c114c20bbd7d292d93415d1e56c8dd6abd3e7Timo Sirainen def all_end
f16c114c20bbd7d292d93415d1e56c8dd6abd3e7Timo Sirainen importer.versions.compact.each do |version|
f16c114c20bbd7d292d93415d1e56c8dd6abd3e7Timo Sirainen version.save!
f16c114c20bbd7d292d93415d1e56c8dd6abd3e7Timo Sirainen version.ontology.update_version!(to: version)
f16c114c20bbd7d292d93415d1e56c8dd6abd3e7Timo Sirainen end
f16c114c20bbd7d292d93415d1e56c8dd6abd3e7Timo Sirainen importer.ontologies.each(&:create_translated_sentences)
f16c114c20bbd7d292d93415d1e56c8dd6abd3e7Timo Sirainen update_ontologies_per_logic_count!(importer.ontologies)
f16c114c20bbd7d292d93415d1e56c8dd6abd3e7Timo Sirainen importer.ontologies.each do |ontology|
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen ontology.__elasticsearch__.index_document
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen ontology.__elasticsearch__.update_document
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen end
8fcff4c5b52f24d9c681805fdf06b486f1d0fcbeTimo Sirainen end
16f816d3f3c32ae3351834253f52ddd0212bcbf3Timo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen def ontology_start(current_element)
98c1cf256927e254f0c092acd2ddcd7ea50bd009Timo Sirainen self.internal_iri = child_name = current_element['name']
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen ontohub_iri = generate_ontology_iri(internal_iri, current_element)
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
84e1634acc701d14e358e27f1beff5ad74f5004aTimo Sirainen initiate_concurrency_handling(ontohub_iri)
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
98c1cf256927e254f0c092acd2ddcd7ea50bd009Timo Sirainen self.ontology = procure_ontology(current_element, internal_iri)
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
8fcff4c5b52f24d9c681805fdf06b486f1d0fcbeTimo Sirainen ontology.name = ontology.generate_name(current_element['name'])
022412398e56a8f31ef111cfd7271498d64af9a9Timo Sirainen
98c1cf256927e254f0c092acd2ddcd7ea50bd009Timo Sirainen assign_language(ontology, current_element)
8fcff4c5b52f24d9c681805fdf06b486f1d0fcbeTimo Sirainen assign_logic(ontology, current_element)
9aa52288a4b53186d81b0ec9afa7d9e0a8ee8753Timo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen ontology.save!
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
e06c0b65c16ccce69bbee009ead14d7d3d17a256Timo Sirainen altIri = ontology.alternative_iris.where(iri: internal_iri).
7a6b45405fb1544ac476e6eb1402a70cc1ddcdcfTimo Sirainen first_or_create(ontology: ontology)
e05ea8311ae16687295048e88ca205dfe29fbcbfTimo Sirainen
8fcff4c5b52f24d9c681805fdf06b486f1d0fcbeTimo Sirainen self.logic_callback = ParsingCallback.determine_for(ontology)
8fcff4c5b52f24d9c681805fdf06b486f1d0fcbeTimo Sirainen
98c1cf256927e254f0c092acd2ddcd7ea50bd009Timo Sirainen logic_callback.ontology(current_element, ontology)
98c1cf256927e254f0c092acd2ddcd7ea50bd009Timo Sirainen end
f7d43647acc6dc80064c8c4cacf5bf86f754c530Timo Sirainen
98c1cf256927e254f0c092acd2ddcd7ea50bd009Timo Sirainen def ontology_end(*ignore_args)
98c1cf256927e254f0c092acd2ddcd7ea50bd009Timo Sirainen logic_callback.ontology_end({}, ontology)
98c1cf256927e254f0c092acd2ddcd7ea50bd009Timo Sirainen
98c1cf256927e254f0c092acd2ddcd7ea50bd009Timo Sirainen ontology.current_version.state = 'done' if ontology.parent
98c1cf256927e254f0c092acd2ddcd7ea50bd009Timo Sirainen ontology.save!
a2637488c8d514ec1ac3914811deee814f9761b3Timo Sirainen
a2637488c8d514ec1ac3914811deee814f9761b3Timo Sirainen ontology.sentences.original.find_each(&:set_display_text!)
a2637488c8d514ec1ac3914811deee814f9761b3Timo Sirainen
a2637488c8d514ec1ac3914811deee814f9761b3Timo Sirainen finish_concurrency_handling
a2637488c8d514ec1ac3914811deee814f9761b3Timo Sirainen end
b6d817f0effeff645aadc01fd468a7d4084ba1f2Timo Sirainen
a2637488c8d514ec1ac3914811deee814f9761b3Timo Sirainen def symbol(current_element)
a2637488c8d514ec1ac3914811deee814f9761b3Timo Sirainen if logic_callback.pre_symbol(current_element)
a2637488c8d514ec1ac3914811deee814f9761b3Timo Sirainen symbol = ontology.symbols.update_or_create_from_hash(
a2637488c8d514ec1ac3914811deee814f9761b3Timo Sirainen current_element, importer.now)
a2637488c8d514ec1ac3914811deee814f9761b3Timo Sirainen ontology.symbols_count += 1
a2637488c8d514ec1ac3914811deee814f9761b3Timo Sirainen
a2637488c8d514ec1ac3914811deee814f9761b3Timo Sirainen logic_callback.symbol(current_element, symbol)
a2637488c8d514ec1ac3914811deee814f9761b3Timo Sirainen end
a2637488c8d514ec1ac3914811deee814f9761b3Timo Sirainen end
a2637488c8d514ec1ac3914811deee814f9761b3Timo Sirainen
a2637488c8d514ec1ac3914811deee814f9761b3Timo Sirainen def axiom(current_element)
a2637488c8d514ec1ac3914811deee814f9761b3Timo Sirainen if logic_callback.pre_axiom(current_element)
02b79f9c2636da1829eee5b92753602bba8b67edTimo Sirainen axiom = ontology.axioms.update_or_create_from_hash(
02b79f9c2636da1829eee5b92753602bba8b67edTimo Sirainen current_element, importer.now)
02b79f9c2636da1829eee5b92753602bba8b67edTimo Sirainen ontology.axioms_count += 1
a2637488c8d514ec1ac3914811deee814f9761b3Timo Sirainen ontology.sentences_count += 1
02b79f9c2636da1829eee5b92753602bba8b67edTimo Sirainen
02b79f9c2636da1829eee5b92753602bba8b67edTimo Sirainen logic_callback.axiom(current_element, axiom)
b5e6f6f27c1461f0f9f202615eeb738a645188c3Timo Sirainen end
02b79f9c2636da1829eee5b92753602bba8b67edTimo Sirainen end
02b79f9c2636da1829eee5b92753602bba8b67edTimo Sirainen
02b79f9c2636da1829eee5b92753602bba8b67edTimo Sirainen def imported_axiom(current_element)
02b79f9c2636da1829eee5b92753602bba8b67edTimo Sirainen if logic_callback.pre_axiom(current_element)
02b79f9c2636da1829eee5b92753602bba8b67edTimo Sirainen current_element['imported'] = true
a2637488c8d514ec1ac3914811deee814f9761b3Timo Sirainen axiom = ontology.axioms.update_or_create_from_hash(
299183fbb6ec5d0828a0880da372540421ac4665Timo Sirainen current_element, importer.now)
299183fbb6ec5d0828a0880da372540421ac4665Timo Sirainen ontology.axioms_count += 1
299183fbb6ec5d0828a0880da372540421ac4665Timo Sirainen ontology.sentences_count += 1
a2637488c8d514ec1ac3914811deee814f9761b3Timo Sirainen
a2637488c8d514ec1ac3914811deee814f9761b3Timo Sirainen logic_callback.axiom(current_element, axiom)
299183fbb6ec5d0828a0880da372540421ac4665Timo Sirainen end
299183fbb6ec5d0828a0880da372540421ac4665Timo Sirainen end
a2637488c8d514ec1ac3914811deee814f9761b3Timo Sirainen
299183fbb6ec5d0828a0880da372540421ac4665Timo Sirainen def theorem(current_element)
299183fbb6ec5d0828a0880da372540421ac4665Timo Sirainen if logic_callback.pre_theorem(current_element)
299183fbb6ec5d0828a0880da372540421ac4665Timo Sirainen theorem = ontology.theorems.update_or_create_from_hash(
299183fbb6ec5d0828a0880da372540421ac4665Timo Sirainen current_element, importer.now)
6288d3611eda14a017dae9927b73f46afb646c96Timo Sirainen ontology.theorems_count += 1
a2637488c8d514ec1ac3914811deee814f9761b3Timo Sirainen ontology.sentences_count += 1
299183fbb6ec5d0828a0880da372540421ac4665Timo Sirainen
299183fbb6ec5d0828a0880da372540421ac4665Timo Sirainen logic_callback.theorem(current_element, theorem)
299183fbb6ec5d0828a0880da372540421ac4665Timo Sirainen end
299183fbb6ec5d0828a0880da372540421ac4665Timo Sirainen end
299183fbb6ec5d0828a0880da372540421ac4665Timo Sirainen
299183fbb6ec5d0828a0880da372540421ac4665Timo Sirainen def mapping(current_element)
299183fbb6ec5d0828a0880da372540421ac4665Timo Sirainen if logic_callback.pre_mapping(current_element)
299183fbb6ec5d0828a0880da372540421ac4665Timo Sirainen alias_iris_for_mappings!(current_element)
299183fbb6ec5d0828a0880da372540421ac4665Timo Sirainen mapping = parent_ontology.mappings.update_or_create_from_hash(
299183fbb6ec5d0828a0880da372540421ac4665Timo Sirainen current_element, user, importer.now)
299183fbb6ec5d0828a0880da372540421ac4665Timo Sirainen logic_callback.mapping(current_element, mapping)
299183fbb6ec5d0828a0880da372540421ac4665Timo Sirainen end
299183fbb6ec5d0828a0880da372540421ac4665Timo Sirainen end
299183fbb6ec5d0828a0880da372540421ac4665Timo Sirainen
299183fbb6ec5d0828a0880da372540421ac4665Timo Sirainen def import(current_element)
299183fbb6ec5d0828a0880da372540421ac4665Timo Sirainen location = current_element['location']
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen source_iri = location ? location : internal_iri
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen begin
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen commit_oid = ExternalRepository.add_to_repository(
313fe89df4d91cd0cd7f3558dc6d7fd21ad39eeeTimo Sirainen internal_iri,
9e59a1f3f095b3099478562cf3f3970a24736970Timo Sirainen "add reference #{Settings.OMS}: #{internal_iri} from #{source_iri}",
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen user, location: source_iri)
178511b57faa7c3f8203dd8b7e4059d00cbfc23aTimo Sirainen version = ontology.versions.build
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen version.user = user
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen version.do_not_parse!
2e937ed8585299b2e879a28314902a5f644813d2Timo Sirainen version.commit_oid = commit_oid
313fe89df4d91cd0cd7f3558dc6d7fd21ad39eeeTimo Sirainen version.state = 'done'
313fe89df4d91cd0cd7f3558dc6d7fd21ad39eeeTimo Sirainen version.basepath = ontology.basepath
dda2c506c8fc8ac2f88272de4523ded42baa0aa0Timo Sirainen version.file_extension = ontology.file_extension
313fe89df4d91cd0cd7f3558dc6d7fd21ad39eeeTimo Sirainen importer.versions << version
313fe89df4d91cd0cd7f3558dc6d7fd21ad39eeeTimo Sirainen rescue
4d25408732be27e91f0430f71e87242760c2517cTimo Sirainen ontology.present = false
e68309fcfa2eaa88217fd51e7b4900fc9c20ef5dTimo Sirainen end
313fe89df4d91cd0cd7f3558dc6d7fd21ad39eeeTimo Sirainen end
313fe89df4d91cd0cd7f3558dc6d7fd21ad39eeeTimo Sirainen end
313fe89df4d91cd0cd7f3558dc6d7fd21ad39eeeTimo Sirainen end
e5c08648676d1989f6e70b95e5990c26b3e8b96bTimo Sirainenend
4d25408732be27e91f0430f71e87242760c2517cTimo Sirainen