Class: SimpleInlineTextAnnotation
- Inherits:
-
Object
- Object
- SimpleInlineTextAnnotation
- Defined in:
- lib/simple_inline_text_annotation.rb,
lib/simple_inline_text_annotation/parser.rb,
lib/simple_inline_text_annotation/version.rb,
lib/simple_inline_text_annotation/generator.rb,
lib/simple_inline_text_annotation/denotation.rb,
lib/simple_inline_text_annotation/generator_error.rb,
lib/simple_inline_text_annotation/relation_validator.rb,
lib/simple_inline_text_annotation/denotation_validator.rb,
lib/simple_inline_text_annotation/entity_type_collection.rb,
lib/simple_inline_text_annotation/relation_without_denotation_error.rb
Defined Under Namespace
Modules: DenotationValidator, RelationValidator Classes: Denotation, EntityTypeCollection, Generator, GeneratorError, Parser, RelationWithoutDenotationError
Constant Summary collapse
- ENTITY_TYPE_PATTERN =
ENTITY_TYPE_PATTERN matches a pair of square brackets which is followed by a colon and URL. Similar to Markdown, this also matches when there is text enclosed in “” or ” after the URL. Match example:
- [Label]: URL - [Label]: URL "text" /^\s*\[([^\]]+)\]:\s+(\S+)(?:\s+(?:"[^"]*"|'[^']*'))?\s*$/- ENTITY_TYPE_BLOCK_PATTERN =
ENTITY_TYPE_BLOCK_PATTERN matches a block of the entity type definitions. Requires a blank line above the block definition.
/(?:\A|\n\s*\n)((?:#{ENTITY_TYPE_PATTERN}(?:\n|$))+)/- ESCAPE_PATTERN =
ESCAPE_PATTERN matches a backslash () preceding two consecutive pairs of square brackets. Example: [This is a part of][original text]
/\\(?=\[[^\]]+\]\[[^\]]+\])/- VERSION =
"2.1.0"
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(text, denotations, relations, entity_type_collection) ⇒ SimpleInlineTextAnnotation
constructor
A new instance of SimpleInlineTextAnnotation.
- #to_h ⇒ Object
Constructor Details
#initialize(text, denotations, relations, entity_type_collection) ⇒ SimpleInlineTextAnnotation
Returns a new instance of SimpleInlineTextAnnotation.
23 24 25 26 27 28 29 |
# File 'lib/simple_inline_text_annotation.rb', line 23 def initialize(text, denotations, relations, entity_type_collection) @text = text @denotations = denotations @relations = relations @entity_type_collection = entity_type_collection check_denotations_and_relations end |
Class Method Details
.generate(source) ⇒ Object
36 37 38 |
# File 'lib/simple_inline_text_annotation.rb', line 36 def self.generate(source) SimpleInlineTextAnnotation::Generator.new(source).generate end |
.parse(source) ⇒ Object
31 32 33 34 |
# File 'lib/simple_inline_text_annotation.rb', line 31 def self.parse(source) result = SimpleInlineTextAnnotation::Parser.new(source).parse result.to_h end |
Instance Method Details
#to_h ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'lib/simple_inline_text_annotation.rb', line 40 def to_h { "text" => format_text(@text), "denotations" => @denotations.map(&:to_h), "relations" => @relations.empty? ? nil : @relations, "config" => config }.compact end |