Module: BEL::Nanopub
- Included in:
- BELRDF::Reader::NanopubYielder, Translator::Plugins::Xbel::NanopubHandler, BELRDF::Reader::NanopubYielder
- Defined in:
- lib/bel/nanopub/util.rb,
lib/bel/nanopub/nanopub.rb,
lib/bel/nanopub/support.rb,
lib/bel/nanopub/citation.rb,
lib/bel/nanopub/metadata.rb,
lib/bel/nanopub/references.rb,
lib/bel/nanopub/map_references.rb,
lib/bel/nanopub/experiment_context.rb,
lib/bel/nanopub/hash_map_references.rb,
lib/bel/nanopub/map_references_combiner.rb,
lib/bel/nanopub/buffering_nanopub_combiner.rb,
lib/bel/nanopub/streaming_nanopub_combiner.rb
Defined Under Namespace
Modules: MapReferences Classes: BufferingNanopubCombiner, Citation, ExperimentContext, HashMapReferences, MapReferencesCombiner, Metadata, Nanopub, Parameter, References, Statement, StreamingNanopubCombiner, Support, Term
Class Method Summary collapse
- .union_annotation_references(destination, source, suffix = 'incr') ⇒ Object
-
.union_by_keyword(destination, source, suffix = 'incr') ⇒ Array<Array<Hash>,Hash>
Combines annotation/namespace references together by disambiguating the keywords.
- .union_namespace_references(destination, source, suffix = 'incr') ⇒ Object
Class Method Details
.union_annotation_references(destination, source, suffix = 'incr') ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/bel/nanopub/util.rb', line 12 def self.union_annotation_references(destination, source, suffix = 'incr') BEL::Nanopub.union_by_keyword( destination, source, suffix ) end |
.union_by_keyword(destination, source, suffix = 'incr') ⇒ Array<Array<Hash>,Hash>
Combines annotation/namespace references together by disambiguating the keywords. The references in @source@ are combined into @destination@.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/bel/nanopub/util.rb', line 32 def self.union_by_keyword(destination, source, suffix = 'incr') # find new new = source - destination suffix_pattern = /#{Regexp.escape(suffix)}([0-9]+)$/ remap_result = {} combined = destination + new.map { |new_obj| new_key = new_obj.keyword # find a match where the keyword differs match_by_value = destination.find { |dest| new_obj.domain_equal?(dest) } rewrite_key = if match_by_value match_by_value.keyword else # find max suffix match max_suffix = destination.map { |dest| key, suffix_number = dest.keyword.to_s.split(suffix_pattern) if new_key == key suffix_number else nil end }.compact.max { |suffix_number| suffix_number.to_i } if max_suffix new_key + suffix + max_suffix.next else if destination.any? { |dest| dest.keyword == new_key } "#{new_key}#{suffix}1" else new_key end end end rewrite_obj = new_obj.dup rewrite_obj.keyword = rewrite_key remap_result[new_obj] = rewrite_obj rewrite_obj } combined.uniq! [combined, remap_result] end |
.union_namespace_references(destination, source, suffix = 'incr') ⇒ Object
4 5 6 7 8 9 10 |
# File 'lib/bel/nanopub/util.rb', line 4 def self.union_namespace_references(destination, source, suffix = 'incr') BEL::Nanopub.union_by_keyword( destination, source, suffix ) end |