simple_inline_text_annotation 1.1.1 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +5 -1
- data/lib/simple_inline_text_annotation/denotation.rb +2 -2
- data/lib/simple_inline_text_annotation/entity_type_collection.rb +3 -3
- data/lib/simple_inline_text_annotation/generator_error.rb +1 -1
- data/lib/simple_inline_text_annotation/parser.rb +7 -7
- data/lib/simple_inline_text_annotation/relation_without_denotation_error.rb +5 -0
- data/lib/simple_inline_text_annotation/version.rb +1 -1
- data/lib/simple_inline_text_annotation.rb +21 -5
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: afa33452d357e5a3a6c59e9283111d87cad5b3153e97c759e59b98efed7ec18a
|
4
|
+
data.tar.gz: 3ad0707815cbad9040153cee41c6e54761f32364bec3c9780f23d7a119c2e2b5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 22726d0174ed12d50a435d038d6f78adb2bc51062c692d94704705b511cbaffbbfa47c1b4d997bed6519bcf1eb30dc200fbd8380fc3887444fa5bd45668cf524
|
7
|
+
data.tar.gz: 45d9bc60245dc1f91b72f77110ce04b4b00010c674b1b2be61c46f3499683cf392451279cc126e6d24518a14dedfe4919f23615f6a963c8d0267a77096f73d6d
|
data/.rubocop.yml
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
AllCops:
|
2
|
-
TargetRubyVersion: 3.
|
2
|
+
TargetRubyVersion: 3.4.4
|
3
|
+
NewCops: enable
|
3
4
|
|
4
5
|
Style/StringLiterals:
|
5
6
|
EnforcedStyle: double_quotes
|
@@ -13,3 +14,6 @@ Style/Documentation:
|
|
13
14
|
Metrics/BlockLength:
|
14
15
|
Exclude:
|
15
16
|
- 'spec/**/*'
|
17
|
+
|
18
|
+
Gemspec/RequireMFA:
|
19
|
+
Enabled: false
|
@@ -15,11 +15,11 @@ class SimpleInlineTextAnnotation
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def span
|
18
|
-
{ begin
|
18
|
+
{ "begin" => @begin_pos, "end" => @end_pos }
|
19
19
|
end
|
20
20
|
|
21
21
|
def to_h
|
22
|
-
{ id
|
22
|
+
{ "id" => @id, "span" => span, "obj" => @obj }.compact
|
23
23
|
end
|
24
24
|
|
25
25
|
def nested_within?(other)
|
@@ -20,12 +20,12 @@ class SimpleInlineTextAnnotation
|
|
20
20
|
# to_config returns a Array of hashes of each entity type.
|
21
21
|
# Example:
|
22
22
|
# [
|
23
|
-
# {id
|
24
|
-
# {id
|
23
|
+
# {"id" => "https://example.com/Person", "label" => "Person"},
|
24
|
+
# {"id" => "https://example.com/Organization", "label" => "Organization"}
|
25
25
|
# ]
|
26
26
|
def to_config
|
27
27
|
entity_types.map do |label, id|
|
28
|
-
{ id
|
28
|
+
{ "id" => id, "label" => label }
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
require_relative "entity_type_collection"
|
4
4
|
require_relative "denotation"
|
5
|
+
require_relative "relation_without_denotation_error"
|
5
6
|
|
6
7
|
class SimpleInlineTextAnnotation
|
7
8
|
class Parser
|
@@ -21,12 +22,10 @@ class SimpleInlineTextAnnotation
|
|
21
22
|
|
22
23
|
process_annotations(full_text)
|
23
24
|
|
24
|
-
SimpleInlineTextAnnotation.new
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
@entity_type_collection
|
29
|
-
)
|
25
|
+
SimpleInlineTextAnnotation.new full_text,
|
26
|
+
@denotations,
|
27
|
+
@relations,
|
28
|
+
@entity_type_collection
|
30
29
|
end
|
31
30
|
|
32
31
|
private
|
@@ -58,6 +57,7 @@ class SimpleInlineTextAnnotation
|
|
58
57
|
return match.end(0) unless process_annotation(match[2], begin_pos, end_pos)
|
59
58
|
|
60
59
|
full_text[match.begin(0)...match.end(0)] = target_text
|
60
|
+
|
61
61
|
end_pos
|
62
62
|
end
|
63
63
|
|
@@ -89,7 +89,7 @@ class SimpleInlineTextAnnotation
|
|
89
89
|
subj, label, pred, obj2 = annotations
|
90
90
|
obj = get_obj_for(label)
|
91
91
|
@denotations << Denotation.new(begin_pos, end_pos, obj, subj)
|
92
|
-
@relations << { pred
|
92
|
+
@relations << { "pred" => pred, "subj" => subj, "obj" => obj2 }
|
93
93
|
end
|
94
94
|
end
|
95
95
|
end
|
@@ -25,6 +25,7 @@ class SimpleInlineTextAnnotation
|
|
25
25
|
@denotations = denotations
|
26
26
|
@relations = relations
|
27
27
|
@entity_type_collection = entity_type_collection
|
28
|
+
check_denotations_and_relations
|
28
29
|
end
|
29
30
|
|
30
31
|
def self.parse(source)
|
@@ -38,10 +39,10 @@ class SimpleInlineTextAnnotation
|
|
38
39
|
|
39
40
|
def to_h
|
40
41
|
{
|
41
|
-
text
|
42
|
-
denotations
|
43
|
-
relations
|
44
|
-
config
|
42
|
+
"text" => format_text(@text),
|
43
|
+
"denotations" => @denotations.map(&:to_h),
|
44
|
+
"relations" => @relations.empty? ? nil : @relations,
|
45
|
+
"config" => config
|
45
46
|
}.compact
|
46
47
|
end
|
47
48
|
|
@@ -68,6 +69,21 @@ class SimpleInlineTextAnnotation
|
|
68
69
|
def config
|
69
70
|
return nil unless @entity_type_collection.any?
|
70
71
|
|
71
|
-
{ "entity types"
|
72
|
+
{ "entity types" => @entity_type_collection.to_config }
|
73
|
+
end
|
74
|
+
|
75
|
+
def check_denotations_and_relations
|
76
|
+
@relations.each do |relation|
|
77
|
+
unless referable_to?(relation, @denotations)
|
78
|
+
raise SimpleInlineTextAnnotation::RelationWithoutDenotationError,
|
79
|
+
"Relation #{relation.inspect} refers to missing denotation."
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def referable_to?(relation, denotations)
|
85
|
+
denotation_ids = denotations.map(&:id)
|
86
|
+
|
87
|
+
denotation_ids.include?(relation["subj"]) && denotation_ids.include?(relation["obj"])
|
72
88
|
end
|
73
89
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_inline_text_annotation
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- xaiBUh29wX
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-05
|
11
|
+
date: 2025-08-05 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: This gem provides inline text annotation functionality, extracted from
|
14
14
|
PubAnnotation, with support for denotations, entity types, and nested spans.
|
@@ -33,6 +33,7 @@ files:
|
|
33
33
|
- lib/simple_inline_text_annotation/generator_error.rb
|
34
34
|
- lib/simple_inline_text_annotation/parser.rb
|
35
35
|
- lib/simple_inline_text_annotation/relation_validator.rb
|
36
|
+
- lib/simple_inline_text_annotation/relation_without_denotation_error.rb
|
36
37
|
- lib/simple_inline_text_annotation/version.rb
|
37
38
|
- sig/simple_inline_text_annotation.rbs
|
38
39
|
homepage: https://github.com/pubannotation/simple_inline_annotation_format
|
@@ -50,7 +51,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
50
51
|
requirements:
|
51
52
|
- - ">="
|
52
53
|
- !ruby/object:Gem::Version
|
53
|
-
version: 3.
|
54
|
+
version: 3.4.4
|
54
55
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
56
|
requirements:
|
56
57
|
- - ">="
|