node_evaluation_helper.rb revision 120a4f90c07b4fdcdb5a856982a64a604ea98094
70N/Amodule Hets
70N/A module DG
286N/A module NodeEvaluationHelper
70N/A def clean_ontology(ontology)
70N/A ontology.symbols.destroy_all
70N/A ontology.all_sentences.destroy_all
70N/A ontology.symbols_count = 0
70N/A ontology.sentences_count = 0
70N/A ontology.axioms_count = 0
70N/A ontology.theorems_count = 0
70N/A ontology.save!
70N/A end
70N/A
70N/A def assign_language(ontology, current_element)
70N/A if current_element['language']
70N/A iri = "http://purl.net/dol/language/#{current_element['language']}"
70N/A ontology.language = Language.where(iri: iri)
70N/A .first_or_create(user: user, name: current_element['language'])
70N/A end
70N/A end
70N/A
70N/A def assign_logic(ontology, current_element)
70N/A if current_element['logic']
70N/A iri = "http://purl.net/dol/logics/#{current_element['logic']}"
70N/A ontology.logic = Logic.where(iri: iri)
70N/A .first_or_create(user: user, name: current_element['logic'])
70N/A end
70N/A end
70N/A
70N/A def assign_distributed_ontology_logic(ontology)
359N/A iri = "http://purl.net/dol/logics/#{Logic::DEFAULT_DISTRIBUTED_ONTOLOGY_LOGIC}"
70N/A name = Logic::DEFAULT_DISTRIBUTED_ONTOLOGY_LOGIC
70N/A ontology.logic = Logic.where(iri: iri)
70N/A .first_or_create(user: user, name: name)
359N/A end
359N/A
359N/A def procure_child_ontology(internal_iri)
98N/A # generate IRI for child-ontology
321N/A child_locid = parent_ontology.locid_for_child(internal_iri)
321N/A
213N/A # find or create child-ontology by IRI
304N/A ontology = parent_ontology.children.find_with_locid(child_locid)
325N/A if ontology.nil?
320N/A options = {
332N/A locid: child_locid,
231N/A name: internal_iri,
98N/A basepath: parent_ontology.basepath,
347N/A file_extension: parent_ontology.file_extension,
346N/A repository_id: parent_ontology.repository_id,
324N/A present: true,
347N/A }
310N/A ontology = SingleOntology.create!(options, without_protection: true)
316N/A parent_ontology.children << ontology
290N/A end
332N/A
332N/A version = ontology.versions.build
332N/A version.user = user
210N/A version.basepath = ontology.basepath
128N/A version.parent = parent_version
326N/A version.commit_oid = parent_version.try(:commit_oid)
335N/A version.commit = parent_version.try(:commit)
70N/A version.file_extension = ontology.file_extension
294N/A # This version will not exist if the parsing fails
98N/A version.do_not_parse!
277N/A
356N/A importer.versions << version
289N/A
326N/A ontology
290N/A end
286N/A
90N/A def parent_version
295N/A importer.version if parent_ontology
70N/A end
299N/A
262N/A def alias_iris_for_mappings!(current_element)
277N/A aliases = importer.ontology_aliases
332N/A current_element['source_iri'] = aliases[current_element['source']]
332N/A current_element['target_iri'] = aliases[current_element['target']]
70N/A end
70N/A
319N/A def generate_ontology_iri(internal_iri, current_element)
280N/A if current_element['reference'] == 'true'
319N/A ontology = Ontology.find_with_iri(internal_iri)
359N/A if ontology.nil?
359N/A ontohub_iri = ExternalRepository.determine_iri(internal_iri)
70N/A else
98N/A ontohub_iri = ontology.iri
98N/A end
231N/A else
98N/A if parent_ontology.distributed?
156N/A ontohub_iri = parent_ontology.locid_for_child(internal_iri)
156N/A else
98N/A # we use 0 here, because the first time around, we
70N/A # have ontologies_count 0 which is increased by one
70N/A # after obtaining the lock. We need to preempt
70N/A # this message, because otherwise we would
70N/A # fail here with a lock issue instead of the
70N/A # 'more than one ontology' issue.
70N/A if importer.ontologies_count > 0
70N/A raise "more than one #{Settings.OMS} found"
70N/A else
70N/A ontohub_iri = parent_ontology.iri
70N/A end
70N/A end
70N/A end
70N/A end
70N/A
70N/A def procure_ontology(element, iri)
70N/A if element['reference'] == 'true'
70N/A ontology = Ontology.find_with_iri(iri)
70N/A if ontology.nil?
253N/A ontology = ExternalRepository.create_ontology(iri)
70N/A end
70N/A importer.ontology_aliases[element['name']] = ontology.iri
else
importer.ontologies_count += 1
if parent_ontology.distributed?
assign_distributed_ontology_logic(parent_ontology)
ontology = procure_child_ontology(iri)
else
ontology = parent_ontology
ontology.present = true
end
end
clean_ontology(ontology)
ontology
end
def code_reference_from_range(range)
return if range.nil?
match = range.match( %r{
(?<begin_line>\d+)\.
(?<begin_column>\d+)
-
(?<end_line>\d+)\.
(?<end_column>\d+)}x)
if match
reference = CodeReference.new(begin_line: match[:begin_line].to_i,
begin_column: match[:begin_column].to_i,
end_line: match[:end_line].to_i,
end_column: match[:end_column].to_i)
end
end
# if it is possible for ontologies to be a relation we should optimize the
# call by using #select instead of #map.
def update_ontologies_per_logic_count!(ontologies)
Logic.where(id: ontologies.map(&:logic_id)).pluck(:id).each do |logic_id|
Logic.reset_counters(logic_id, :ontologies)
end
end
end
end
end