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
Defined Under Namespace
Modules: DenotationValidator, RelationValidator Classes: Denotation, EntityTypeCollection, Generator, GeneratorError, Parser
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 =
"1.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 |
# 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 end |
Class Method Details
.generate(source) ⇒ Object
35 36 37 |
# File 'lib/simple_inline_text_annotation.rb', line 35 def self.generate(source) SimpleInlineTextAnnotation::Generator.new(source).generate end |
.parse(source) ⇒ Object
30 31 32 33 |
# File 'lib/simple_inline_text_annotation.rb', line 30 def self.parse(source) result = SimpleInlineTextAnnotation::Parser.new(source).parse result.to_h end |
Instance Method Details
#to_h ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'lib/simple_inline_text_annotation.rb', line 39 def to_h { text: format_text(@text), denotations: @denotations.map(&:to_h), relations: @relations.empty? ? nil : @relations, config: config }.compact end |