Module: Document
- Extended by:
- Entity
- Defined in:
- lib/rbbt/document.rb,
lib/rbbt/document/annotation.rb
Defined Under Namespace
Modules: Corpus
Class Method Summary collapse
Class Method Details
.define(type, &block) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/rbbt/document/annotation.rb', line 5 def self.define(type, &block) send :property, type do segments = self.instance_exec &block Segment.align(self, segments) unless segments.empty? || (Segment === segments && segments.offset) || (Array === segments && Segment === segments.first && segments.first.offset) segments.each do |segment| SegmentAnnotation.setup(segment, :type => type.to_s) unless SegmentAnnotation === segment && segment.type end docid = self.docid segments.each{|s| s.docid = docid } segments end DocID.property type do self.document.send(type) end SegID.property type do self.overlaps(self.docid.send(type)) end Segment.property type do self.overlaps(self.docid.send(type)) end seg_type = "segids_for_" + type.to_s send :property, seg_type do SegID.setup(self.send(type).collect{|s| s.segid }) end DocID.property seg_type do self.document.send(seg_type) end SegID.property seg_type do self.overlaps(self.docid.send(seg_type)) end Segment.property seg_type do self.overlaps(self.docid.send(seg_type)) end end |
.define_multiple(type, &block) ⇒ Object
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 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/rbbt/document/annotation.rb', line 54 def self.define_multiple(type, &block) send :property, type => :multiple do |list| doc_segments = self.instance_exec list, &block doc_segments = doc_segments.chunked_values_at(list) if Hash === doc_segments doc_segments.each_with_index do |segments,i| next if segments.nil? document = list[i] Segment.align(document, segments) unless segments.nil? || segments.empty? || (Segment === segments && segments.offset) || (Array === segments && Segment === segments.first && segments.first.offset) segments.each do |segment| SegmentAnnotation.setup(segment, :type => type.to_s) unless SegmentAnnotation === segment && segment.type end docid = document.docid segments.each{|s| s.docid = docid } segments end end DocID.property type do self.document.send(type) end SegID.property type do self.overlaps(self.docid.send(type)) end Segment.property type do self.overlaps(self.docid.send(type)) end seg_type = "segids_for_" + type.to_s send :property, seg_type do SegID.setup(self.send(type).collect{|s| s.segid }) end DocID.property seg_type do self.document.send(seg_type) end SegID.property seg_type do self.overlaps(self.docid.send(seg_type)) end Segment.property seg_type do self.overlaps(self.docid.send(seg_type)) end end |