Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
mdorf committed Feb 27, 2024
1 parent e7ed676 commit ef20f3e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 35 deletions.
17 changes: 3 additions & 14 deletions config/solr/term_search/schema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@
<field name="_root_" type="string" indexed="true" stored="false" docValues="false" />
<field name="_text_" type="text_general" indexed="true" stored="false" multiValued="true"/>


<!-- NCBO specific fields -->
<field name="resource_id" type="string" indexed="true" stored="true" multiValued="false" required="true" />

Expand All @@ -139,20 +138,9 @@
<field name="synonymSuggest" type="text_suggest" indexed="true" stored="true" omitNorms="true" multiValued="true" />
<field name="synonymSuggestEdge" type="text_suggest_edge" indexed="true" stored="true" multiValued="true" />
<field name="synonymSuggestNgram" type="text_suggest_ngram" indexed="true" stored="true" omitNorms="true" multiValued="true" />



<field name="notation" type="string_ci" indexed="true" stored="true" multiValued="false" />





<field name="shortId" type="string_ci" indexed="true" stored="true" multiValued="false" />




<field name="oboId" type="string_ci" indexed="true" stored="true" multiValued="false" />
<field name="idAcronymMatch" type="boolean" indexed="true" stored="true" multiValued="false" default="false"/>

<field name="definition" type="string" indexed="true" stored="true" multiValued="true" />
<field name="submissionAcronym" type="string" indexed="true" stored="true" multiValued="false" />
Expand Down Expand Up @@ -264,6 +252,7 @@
<copyField source="synonym" dest="synonymSuggestNgram" />

<copyField source="notation" dest="_text_"/>
<copyField source="oboId" dest="_text_"/>


<!-- field type definitions. The "name" attribute is
Expand Down
53 changes: 32 additions & 21 deletions lib/ontologies_linked_data/models/class.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ def index_doc(to_set=nil)
doc = {}
path_ids = Set.new
self.bring(:submission) if self.bring?(:submission)
class_id = self.id.to_s

if to_set.nil?
begin
Expand All @@ -151,31 +152,33 @@ def index_doc(to_set=nil)
doc[:childCount] = self.childrenCount
rescue Exception => e
doc[:childCount] = 0
puts "Exception getting childCount for search for #{self.id.to_s}: #{e.class}: #{e.message}"
puts "Exception getting childCount for search for #{class_id}: #{e.class}: #{e.message}"
end

begin
# paths_to_root = self.paths_to_root
# paths_to_root.each do |paths|
# path_ids += paths.map { |p| p.id.to_s }
# end
# path_ids.delete(self.id.to_s)
# path_ids.delete(class_id)
path_ids = retrieve_hierarchy_ids(:ancestors)
path_ids.select! { |x| !x["owl#Thing"] }
doc[:parents] = path_ids
rescue Exception => e
doc[:parents] = Set.new
puts "Exception getting paths to root for search for #{self.id.to_s}: #{e.class}: #{e.message}\n#{e.backtrace.join("\n")}"
puts "Exception getting paths to root for search for #{class_id}: #{e.class}: #{e.message}\n#{e.backtrace.join("\n")}"
end

acronym = self.submission.ontology.acronym
doc[:id] = class_id
doc[:ontologyId] = self.submission.id.to_s
doc[:submissionAcronym] = self.submission.ontology.acronym
doc[:submissionAcronym] = acronym
doc[:submissionId] = self.submission.submissionId
doc[:ontologyType] = self.submission.ontology.ontologyType.get_code_from_id
doc[:obsolete] = self.obsolete.to_s

all_attrs = self.to_hash
std = [:id, :prefLabel, :notation, :synonym, :definition, :cui]
std = [:prefLabel, :notation, :synonym, :definition, :cui]

std.each do |att|
cur_val = all_attrs[att]
Expand All @@ -200,14 +203,19 @@ def index_doc(to_set=nil)
all_attrs[:semanticType].each { |semType| doc[:semanticType] << semType.split("/").last }
end

# special handling for :notation field because some ontologies have it defined as :prefixIRI
# mdorf, 2/4/2024: special handling for :notation field because some ontologies have it defined as :prefixIRI
if !doc[:notation] || doc[:notation].empty?
if all_attrs[:prefixIRI] && !all_attrs[:prefixIRI].empty?
doc[:notation] = all_attrs[:prefixIRI].strip
else
doc[:notation] = LinkedData::Utils::Triples::last_iri_fragment(doc[:id])
end
end
doc[:idAcronymMatch] = true if notation_acronym_match(doc[:notation], acronym)
# https://github.com/bmir-radx/radx-project/issues/46
# https://github.com/bmir-radx/radx-project/issues/46#issuecomment-1939782535
# https://github.com/bmir-radx/radx-project/issues/46#issuecomment-1939932614
set_oboid_fields(class_id, self.submission.uri, acronym, doc)
end

if to_set.nil? || (to_set.is_a?(Array) && to_set.include?(:properties))
Expand All @@ -218,26 +226,29 @@ def index_doc(to_set=nil)
doc[:propertyRaw] = props[:propertyRaw]
end
end

# binding.pry

doc
end

def set_oboid_fields(class_id, ontology_iri, ontology_acronym, index_doc)
short_id = LinkedData::Utils::Triples.last_iri_fragment(class_id)
matched = short_id.match(/([A-Za-z]+)_([0-9]+)$/) do |m|
index_doc[:oboId] = "#{m[1]}:#{m[2]}"
index_doc[:idAcronymMatch] = true if m[1].upcase === ontology_acronym.upcase
true
end

if !matched && ontology_iri && class_id.start_with?(ontology_iri)
index_doc[:oboId] = "#{ontology_acronym}:#{short_id}"
index_doc[:idAcronymMatch] = true
end
end













def notation_acronym_match(notation, ontology_acronym)
notation.match(/^([A-Za-z]+)[_:]{1}/) do |m|
return m[1].upcase === ontology_acronym.upcase
end
false
end

def properties_for_indexing()
self_props = self.properties
Expand Down

0 comments on commit ef20f3e

Please sign in to comment.