rdf-n3 3.1.1 → 3.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (124) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +148 -69
  3. data/UNLICENSE +1 -1
  4. data/VERSION +1 -1
  5. data/lib/rdf/n3.rb +8 -8
  6. data/lib/rdf/n3/algebra.rb +147 -68
  7. data/lib/rdf/n3/algebra/builtin.rb +79 -0
  8. data/lib/rdf/n3/algebra/formula.rb +355 -94
  9. data/lib/rdf/n3/algebra/list/append.rb +33 -4
  10. data/lib/rdf/n3/algebra/list/first.rb +24 -0
  11. data/lib/rdf/n3/algebra/list/in.rb +42 -3
  12. data/lib/rdf/n3/algebra/list/last.rb +17 -4
  13. data/lib/rdf/n3/algebra/list/length.rb +24 -0
  14. data/lib/rdf/n3/algebra/list/member.rb +39 -2
  15. data/lib/rdf/n3/algebra/list_operator.rb +83 -0
  16. data/lib/rdf/n3/algebra/log/conclusion.rb +57 -1
  17. data/lib/rdf/n3/algebra/log/conjunction.rb +28 -1
  18. data/lib/rdf/n3/algebra/log/content.rb +34 -0
  19. data/lib/rdf/n3/algebra/log/equal_to.rb +34 -0
  20. data/lib/rdf/n3/algebra/log/implies.rb +55 -30
  21. data/lib/rdf/n3/algebra/log/includes.rb +58 -1
  22. data/lib/rdf/n3/algebra/log/n3_string.rb +34 -0
  23. data/lib/rdf/n3/algebra/log/not_equal_to.rb +23 -0
  24. data/lib/rdf/n3/algebra/log/not_includes.rb +27 -0
  25. data/lib/rdf/n3/algebra/log/output_string.rb +40 -0
  26. data/lib/rdf/n3/algebra/log/parsed_as_n3.rb +36 -0
  27. data/lib/rdf/n3/algebra/log/semantics.rb +40 -0
  28. data/lib/rdf/n3/algebra/math/absolute_value.rb +36 -0
  29. data/lib/rdf/n3/algebra/math/acos.rb +26 -0
  30. data/lib/rdf/n3/algebra/math/acosh.rb +26 -0
  31. data/lib/rdf/n3/algebra/math/asin.rb +26 -0
  32. data/lib/rdf/n3/algebra/math/asinh.rb +26 -0
  33. data/lib/rdf/n3/algebra/math/atan.rb +26 -0
  34. data/lib/rdf/n3/algebra/math/atanh.rb +26 -0
  35. data/lib/rdf/n3/algebra/math/ceiling.rb +28 -0
  36. data/lib/rdf/n3/algebra/math/cos.rb +40 -0
  37. data/lib/rdf/n3/algebra/math/cosh.rb +38 -0
  38. data/lib/rdf/n3/algebra/math/difference.rb +34 -3
  39. data/lib/rdf/n3/algebra/math/equal_to.rb +54 -0
  40. data/lib/rdf/n3/algebra/math/exponentiation.rb +29 -3
  41. data/lib/rdf/n3/algebra/math/floor.rb +28 -0
  42. data/lib/rdf/n3/algebra/math/greater_than.rb +41 -0
  43. data/lib/rdf/n3/algebra/math/less_than.rb +41 -0
  44. data/lib/rdf/n3/algebra/math/negation.rb +31 -2
  45. data/lib/rdf/n3/algebra/math/not_equal_to.rb +25 -0
  46. data/lib/rdf/n3/algebra/math/not_greater_than.rb +25 -0
  47. data/lib/rdf/n3/algebra/math/not_less_than.rb +25 -0
  48. data/lib/rdf/n3/algebra/math/product.rb +14 -3
  49. data/lib/rdf/n3/algebra/math/quotient.rb +30 -3
  50. data/lib/rdf/n3/algebra/math/remainder.rb +29 -3
  51. data/lib/rdf/n3/algebra/math/rounded.rb +20 -3
  52. data/lib/rdf/n3/algebra/math/sin.rb +40 -0
  53. data/lib/rdf/n3/algebra/math/sinh.rb +38 -0
  54. data/lib/rdf/n3/algebra/math/sum.rb +35 -4
  55. data/lib/rdf/n3/algebra/math/tan.rb +40 -0
  56. data/lib/rdf/n3/algebra/math/tanh.rb +38 -0
  57. data/lib/rdf/n3/algebra/not_implemented.rb +13 -0
  58. data/lib/rdf/n3/algebra/resource_operator.rb +123 -0
  59. data/lib/rdf/n3/algebra/str/concatenation.rb +21 -3
  60. data/lib/rdf/n3/algebra/str/contains.rb +28 -4
  61. data/lib/rdf/n3/algebra/str/contains_ignoring_case.rb +33 -0
  62. data/lib/rdf/n3/algebra/str/ends_with.rb +33 -0
  63. data/lib/rdf/n3/algebra/str/equal_ignoring_case.rb +34 -0
  64. data/lib/rdf/n3/algebra/str/format.rb +12 -4
  65. data/lib/rdf/n3/algebra/str/greater_than.rb +38 -0
  66. data/lib/rdf/n3/algebra/str/less_than.rb +33 -0
  67. data/lib/rdf/n3/algebra/str/matches.rb +33 -5
  68. data/lib/rdf/n3/algebra/str/not_equal_ignoring_case.rb +17 -0
  69. data/lib/rdf/n3/algebra/str/not_greater_than.rb +17 -0
  70. data/lib/rdf/n3/algebra/str/not_less_than.rb +17 -0
  71. data/lib/rdf/n3/algebra/str/not_matches.rb +18 -0
  72. data/lib/rdf/n3/algebra/str/replace.rb +28 -5
  73. data/lib/rdf/n3/algebra/str/scrape.rb +31 -5
  74. data/lib/rdf/n3/algebra/str/starts_with.rb +33 -0
  75. data/lib/rdf/n3/algebra/time/day.rb +35 -0
  76. data/lib/rdf/n3/algebra/time/day_of_week.rb +27 -0
  77. data/lib/rdf/n3/algebra/time/gm_time.rb +29 -0
  78. data/lib/rdf/n3/algebra/time/hour.rb +35 -0
  79. data/lib/rdf/n3/algebra/time/in_seconds.rb +59 -0
  80. data/lib/rdf/n3/algebra/time/local_time.rb +29 -0
  81. data/lib/rdf/n3/algebra/time/minute.rb +35 -0
  82. data/lib/rdf/n3/algebra/time/month.rb +35 -0
  83. data/lib/rdf/n3/algebra/time/second.rb +35 -0
  84. data/lib/rdf/n3/algebra/time/timezone.rb +36 -0
  85. data/lib/rdf/n3/algebra/time/year.rb +29 -0
  86. data/lib/rdf/n3/extensions.rb +180 -21
  87. data/lib/rdf/n3/format.rb +65 -0
  88. data/lib/rdf/n3/list.rb +630 -0
  89. data/lib/rdf/n3/reader.rb +762 -485
  90. data/lib/rdf/n3/reasoner.rb +57 -68
  91. data/lib/rdf/n3/refinements.rb +178 -0
  92. data/lib/rdf/n3/repository.rb +332 -0
  93. data/lib/rdf/n3/terminals.rb +80 -0
  94. data/lib/rdf/n3/vocab.rb +35 -7
  95. data/lib/rdf/n3/writer.rb +208 -148
  96. metadata +110 -52
  97. data/AUTHORS +0 -1
  98. data/History.markdown +0 -99
  99. data/lib/rdf/n3/algebra/log/equalTo.rb +0 -7
  100. data/lib/rdf/n3/algebra/log/notEqualTo.rb +0 -7
  101. data/lib/rdf/n3/algebra/log/notIncludes.rb +0 -12
  102. data/lib/rdf/n3/algebra/log/outputString.rb +0 -7
  103. data/lib/rdf/n3/algebra/math/absoluteValue.rb +0 -9
  104. data/lib/rdf/n3/algebra/math/equalTo.rb +0 -9
  105. data/lib/rdf/n3/algebra/math/greaterThan.rb +0 -9
  106. data/lib/rdf/n3/algebra/math/integerQuotient.rb +0 -9
  107. data/lib/rdf/n3/algebra/math/lessThan.rb +0 -9
  108. data/lib/rdf/n3/algebra/math/memberCount.rb +0 -9
  109. data/lib/rdf/n3/algebra/math/notEqualTo.rb +0 -9
  110. data/lib/rdf/n3/algebra/math/notGreaterThan.rb +0 -9
  111. data/lib/rdf/n3/algebra/math/notLessThan.rb +0 -9
  112. data/lib/rdf/n3/algebra/str/containsIgnoringCase.rb +0 -9
  113. data/lib/rdf/n3/algebra/str/endsWith.rb +0 -9
  114. data/lib/rdf/n3/algebra/str/equalIgnoringCase.rb +0 -9
  115. data/lib/rdf/n3/algebra/str/greaterThan.rb +0 -9
  116. data/lib/rdf/n3/algebra/str/lessThan.rb +0 -9
  117. data/lib/rdf/n3/algebra/str/notEqualIgnoringCase.rb +0 -9
  118. data/lib/rdf/n3/algebra/str/notGreaterThan.rb +0 -9
  119. data/lib/rdf/n3/algebra/str/notLessThan.rb +0 -9
  120. data/lib/rdf/n3/algebra/str/notMatches.rb +0 -9
  121. data/lib/rdf/n3/algebra/str/startsWith.rb +0 -56
  122. data/lib/rdf/n3/patches/array_hacks.rb +0 -53
  123. data/lib/rdf/n3/reader/meta.rb +0 -641
  124. data/lib/rdf/n3/reader/parser.rb +0 -239
@@ -0,0 +1,35 @@
1
+ module RDF::N3::Algebra::Time
2
+ ##
3
+ # For a date-time, its time:minute is the minutes component.
4
+ #
5
+ # @see https://www.w3.org/TR/xpath-functions/#func-minutes-from-dateTime
6
+ class Minute < RDF::N3::Algebra::ResourceOperator
7
+ NAME = :timeMinute
8
+ URI = RDF::N3::Time.minute
9
+
10
+ ##
11
+ # The time:minute operator takes string or dateTime and extracts the minute component.
12
+ #
13
+ # @param [RDF::Term] resource
14
+ # @param [:subject, :object] position
15
+ # @return [RDF::Term]
16
+ # @see RDF::N3::ResourceOperator#evaluate
17
+ def resolve(resource, position:)
18
+ case position
19
+ when :subject
20
+ return nil unless resource.literal?
21
+ resource = resource.as_datetime
22
+ RDF::Literal(resource.object.strftime("%M").to_i)
23
+ when :object
24
+ return nil unless resource.literal? || resource.variable?
25
+ resource
26
+ end
27
+ end
28
+
29
+ ##
30
+ # There is no minute unless it was specified in the lexical form
31
+ def valid?(subject, object)
32
+ subject.value.match?(%r(^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}))
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,35 @@
1
+ module RDF::N3::Algebra::Time
2
+ ##
3
+ # For a date-time, its time:month is the two-digit month.
4
+ #
5
+ # @see https://www.w3.org/TR/xpath-functions/#func-month-from-dateTime
6
+ class Month < RDF::N3::Algebra::ResourceOperator
7
+ NAME = :timeMonth
8
+ URI = RDF::N3::Time.month
9
+
10
+ ##
11
+ # The time:month operator takes string or dateTime and extracts the month component.
12
+ #
13
+ # @param [RDF::Term] resource
14
+ # @param [:subject, :object] position
15
+ # @return [RDF::Term]
16
+ # @see RDF::N3::ResourceOperator#evaluate
17
+ def resolve(resource, position:)
18
+ case position
19
+ when :subject
20
+ return nil unless resource.literal?
21
+ resource = resource.as_datetime
22
+ RDF::Literal(resource.object.strftime("%m").to_i)
23
+ when :object
24
+ return nil unless resource.literal? || resource.variable?
25
+ resource
26
+ end
27
+ end
28
+
29
+ ##
30
+ # There is no month unless it was specified in the lexical form
31
+ def valid?(subject, object)
32
+ subject.value.match?(%r(^\d{4}-\d{2}))
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,35 @@
1
+ module RDF::N3::Algebra::Time
2
+ ##
3
+ # For a date-time, its time:second is the seconds component.
4
+ #
5
+ # @see https://www.w3.org/TR/xpath-functions/#func-seconds-from-dateTime
6
+ class Second < RDF::N3::Algebra::ResourceOperator
7
+ NAME = :timeSecond
8
+ URI = RDF::N3::Time.second
9
+
10
+ ##
11
+ # The time:second operator takes string or dateTime and extracts the seconds component.
12
+ #
13
+ # @param [RDF::Term] resource
14
+ # @param [:subject, :object] position
15
+ # @return [RDF::Term]
16
+ # @see RDF::N3::ResourceOperator#evaluate
17
+ def resolve(resource, position:)
18
+ case position
19
+ when :subject
20
+ return nil unless resource.literal?
21
+ resource = resource.as_datetime
22
+ RDF::Literal(resource.object.strftime("%S").to_i)
23
+ when :object
24
+ return nil unless resource.literal? || resource.variable?
25
+ resource
26
+ end
27
+ end
28
+
29
+ ##
30
+ # There is no second unless it was specified in the lexical form
31
+ def valid?(subject, object)
32
+ subject.value.match?(%r(^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}))
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,36 @@
1
+ module RDF::N3::Algebra::Time
2
+ ##
3
+ # For a date-time, its time:timeZone is the trailing timezone offset part, e.g. "-05:00".
4
+ #
5
+ # @see https://www.w3.org/TR/xpath-functions/#func-timezone-from-dateTime
6
+ class Timezone < RDF::N3::Algebra::ResourceOperator
7
+ NAME = :timeTimezone
8
+ URI = RDF::N3::Time.timeZone
9
+
10
+ ##
11
+ # The time:timeZone operator takes string or dateTime and extracts the timeZone component.
12
+ #
13
+ # @param [RDF::Term] resource
14
+ # @param [:subject, :object] position
15
+ # @return [RDF::Term]
16
+ # @see RDF::N3::ResourceOperator#evaluate
17
+ def resolve(resource, position:)
18
+ case position
19
+ when :subject
20
+ return nil unless resource.literal?
21
+ resource = resource.as_datetime
22
+ RDF::Literal(resource.object.strftime("%Z"))
23
+ when :object
24
+ return nil unless resource.literal? || resource.variable?
25
+ resource
26
+ end
27
+ end
28
+
29
+ ##
30
+ # There is no timezone unless it was specified in the lexical form and is not "Z"
31
+ def valid?(subject, object)
32
+ md = subject.value.match(%r(^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(Z|[\+-][\d-]+)))
33
+ md && md[1].to_s != 'Z'
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,29 @@
1
+ module RDF::N3::Algebra::Time
2
+ ##
3
+ # For a date-time, its time:year is the year component.
4
+ #
5
+ # @see https://www.w3.org/TR/xpath-functions/#func-year-from-dateTime
6
+ class Year < RDF::N3::Algebra::ResourceOperator
7
+ NAME = :timeYear
8
+ URI = RDF::N3::Time.year
9
+
10
+ ##
11
+ # The time:year operator takes string or dateTime and extracts the year component.
12
+ #
13
+ # @param [RDF::Term] resource
14
+ # @param [:subject, :object] position
15
+ # @return [RDF::Term]
16
+ # @see RDF::N3::ResourceOperator#evaluate
17
+ def resolve(resource, position:)
18
+ case position
19
+ when :subject
20
+ return nil unless resource.literal?
21
+ resource = resource.as_datetime
22
+ RDF::Literal(resource.object.strftime("%Y").to_i)
23
+ when :object
24
+ return nil unless resource.literal? || resource.variable?
25
+ resource
26
+ end
27
+ end
28
+ end
29
+ end
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
  require 'rdf'
3
+ require 'rdf/n3/terminals'
3
4
 
4
5
  # Monkey-patch RDF::Enumerable to add `:existentials` and `:univerals` accessors
5
6
  module RDF
@@ -11,27 +12,21 @@ module RDF
11
12
  # Universal quantifiers defined on this enumerable
12
13
  # @return [Array<RDF::Query::Variable>]
13
14
  attr_accessor :universals
15
+ end
14
16
 
17
+ class List
15
18
  ##
16
- # An enumerable contains another enumerable if every statement in other is a statement in self
19
+ # A list is variable if any of its members are variable?
17
20
  #
18
- # @param [RDF::Enumerable] other
19
21
  # @return [Boolean]
20
- def contain?(other)
21
- other.all? {|statement| has_statement?(statement)}
22
- end
23
- end
24
-
25
- class Statement
26
- # Override variable?
27
22
  def variable?
28
- to_a.any? {|term| !term.is_a?(RDF::Term) || term.variable?} || graph_name && graph_name.variable?
23
+ to_a.any?(&:variable?)
29
24
  end
30
25
 
31
26
  # Transform Statement into an SXP
32
27
  # @return [Array]
33
28
  def to_sxp_bin
34
- [(variable? ? :pattern : :triple), subject, predicate, object, graph_name].compact
29
+ to_a.to_sxp_bin
35
30
  end
36
31
 
37
32
  ##
@@ -39,24 +34,188 @@ module RDF
39
34
  #
40
35
  # @return [String]
41
36
  def to_sxp
42
- to_sxp_bin.to_sxp
37
+ to_a.to_sxp_bin.to_sxp
43
38
  end
44
39
  end
45
40
 
46
- class Query::Solution
41
+ module Value
42
+ ##
43
+ # Returns `true` if `self` is a {RDF::N3::Algebra::Formula}.
44
+ #
45
+ # @return [Boolean]
46
+ def formula?
47
+ false
48
+ end
47
49
 
48
- # Transform Statement into an SXP
49
- # @return [Array]
50
- def to_sxp_bin
51
- [:solution] + bindings.map {|k, v| Query::Variable.new(k, v).to_sxp_bin}
50
+ # By default, returns itself. Can be used for terms such as blank nodes to be turned into non-disinguished variables.
51
+ #
52
+ # @param [RDF::Node] scope
53
+ # return [RDF::Query::Variable]
54
+ def to_ndvar(scope)
55
+ self
56
+ end
57
+ end
58
+
59
+ module Term
60
+ ##
61
+ # Is this the same term? Like `#eql?`, but no variable matching
62
+ def sameTerm?(other)
63
+ eql?(other)
52
64
  end
53
65
 
54
66
  ##
55
- # Returns an S-Expression (SXP) representation
67
+ # Parse the value as a numeric literal, or return 0.
56
68
  #
57
- # @return [String]
58
- def to_sxp
59
- to_sxp_bin.to_sxp
69
+ # @return [RDF::Literal::Numeric]
70
+ def as_number
71
+ RDF::Literal(0)
72
+ end
73
+
74
+ ##
75
+ # Parse the value as a dateTime literal, or return now.
76
+ #
77
+ # @return [RDF::Literal::DateTime]
78
+ def as_datetime
79
+ RDF::Literal::DateTime.new(DateTime.now)
80
+ end
81
+ end
82
+
83
+ class Literal
84
+ include RDF::N3::Terminals
85
+
86
+ ##
87
+ # Parse the value as a numeric literal, or return 0.
88
+ #
89
+ # @return [RDF::Literal::Numeric]
90
+ def as_number
91
+ return self if self.is_a?(RDF::Literal::Numeric)
92
+ case value
93
+ when DOUBLE then RDF::Literal::Double.new(value)
94
+ when DECIMAL then RDF::Literal::Decimal.new(value)
95
+ when INTEGER then RDF::Literal::Integer.new(value)
96
+ else
97
+ RDF::Literal(0)
98
+ end
99
+ end
100
+
101
+ ##
102
+ # Parse the value as a dateTime literal, or return now.
103
+ #
104
+ # @return [RDF::Literal::DateTime]
105
+ def as_datetime
106
+ return self if is_a?(RDF::Literal::DateTime)
107
+ mvalue = value
108
+ mvalue = "#{mvalue}-01" if mvalue.match?(%r(^\d{4}$))
109
+ mvalue = "#{mvalue}-01" if mvalue.match?(%r(^\d{4}-\d{2}$))
110
+ RDF::Literal::DateTime.new(::DateTime.iso8601(mvalue), lexical: value)
111
+ rescue
112
+ RDF::Literal(0)
113
+ end
114
+ end
115
+
116
+ class Node
117
+ # Transform to a nondistinguished exisetntial variable in a formula scope
118
+ #
119
+ # @param [RDF::Node] scope
120
+ # return [RDF::Query::Variable]
121
+ def to_ndvar(scope)
122
+ label = "#{id}_#{scope ? scope.id : 'base'}_undext"
123
+ RDF::Query::Variable.new(label, existential: true, distinguished: false)
124
+ end
125
+ end
126
+
127
+ class Query
128
+ class Pattern
129
+ ##
130
+ # Overrides `#initialize!` to turn blank nodes into non-distinguished variables, if the `:ndvars` option is set.
131
+ alias_method :orig_initialize!, :initialize!
132
+ def initialize!
133
+ if @options[:ndvars]
134
+ @graph_name = @graph_name.to_ndvar(nil) if @graph_name
135
+ @subject = @subject.to_ndvar(@graph_name)
136
+ @predicate = @predicate.to_ndvar(@graph_name)
137
+ @object = @object.to_ndvar(@graph_name)
138
+ end
139
+ orig_initialize!
140
+ end
141
+
142
+ ##
143
+ # Checks pattern equality against a statement, considering nesting an lists.
144
+ #
145
+ # * A pattern which has a pattern as a subject or an object, matches
146
+ # a statement having a statement as a subject or an object using {#eql?}.
147
+ #
148
+ # @param [Statement] other
149
+ # @return [Boolean]
150
+ #
151
+ # @see RDF::URI#==
152
+ # @see RDF::Node#==
153
+ # @see RDF::Literal#==
154
+ # @see RDF::Query::Variable#==
155
+ def eql?(other)
156
+ return false unless other.is_a?(RDF::Statement) && (self.graph_name || false) == (other.graph_name || false)
157
+
158
+ [:subject, :predicate, :object].each do |part|
159
+ case o = self.send(part)
160
+ when RDF::Query::Pattern, RDF::List
161
+ return false unless o.eql?(other.send(part))
162
+ else
163
+ return false unless o == other.send(part)
164
+ end
165
+ end
166
+ true
167
+ end
168
+ end
169
+
170
+ class Solution
171
+ # Transform Statement into an SXP
172
+ # @return [Array]
173
+ def to_sxp_bin
174
+ [:solution] + bindings.map do |k, v|
175
+ existential = k.to_s.end_with?('ext')
176
+ k = k.to_s.sub(/_(?:und)?ext$/, '').to_sym
177
+ distinguished = !k.to_s.end_with?('undext')
178
+ Query::Variable.new(k, v, existential: existential, distinguished: distinguished).to_sxp_bin
179
+ end
180
+ end
181
+ end
182
+
183
+ class Variable
184
+ ##
185
+ # True if the other is the same variable
186
+ def sameTerm?(other)
187
+ other.is_a?(::RDF::Query::Variable) && name.eql?(other.name)
188
+ end
189
+
190
+ ##
191
+ # Parse the value as a numeric literal, or return 0.
192
+ #
193
+ # @return [RDF::Literal::Numeric]
194
+ def as_number
195
+ RDF::Literal(0)
196
+ end
197
+ end
198
+ end
199
+ end
200
+
201
+ module SPARQL
202
+ module Algebra
203
+ class Operator
204
+ ##
205
+ # Map of related formulae, indexed by graph name.
206
+ #
207
+ # @return [Hash{RDF::Resource => RDF::N3::Algebra::Formula}]
208
+ def formulae
209
+ @options.fetch(:formulae, {})
210
+ end
211
+
212
+ # Updates the operands for this operator.
213
+ #
214
+ # @param [Array] ary
215
+ # @return [Array]
216
+ def operands=(ary)
217
+ @operands = ary
218
+ end
60
219
  end
61
220
  end
62
221
  end
@@ -27,5 +27,70 @@ module RDF::N3
27
27
  def self.symbols
28
28
  [:n3, :notation3]
29
29
  end
30
+
31
+ ##
32
+ # Hash of CLI commands appropriate for this format
33
+ # @return [Hash{Symbol => Hash}]
34
+ def self.cli_commands
35
+ {
36
+ reason: {
37
+ description: "Reason over formulae.",
38
+ help: "reason [--think] file\nPerform Notation-3 reasoning.",
39
+ parse: false,
40
+ # Only shows when input and output format set
41
+ filter: {format: :n3},
42
+ repository: RDF::N3::Repository.new,
43
+ lambda: ->(argv, **options) do
44
+ repository = options[:repository]
45
+ result_repo = RDF::N3::Repository.new
46
+ RDF::CLI.parse(argv, format: :n3, list_terms: true, **options) do |reader|
47
+ reasoner = RDF::N3::Reasoner.new(reader, **options)
48
+ reasoner.reason!(**options)
49
+ if options[:conclusions]
50
+ result_repo << reasoner.conclusions
51
+ elsif options[:data]
52
+ result_repo << reasoner.data
53
+ else
54
+ result_repo << reasoner
55
+ end
56
+ end
57
+
58
+ # Replace input repository with results
59
+ repository.clear!
60
+ repository << result_repo
61
+ end,
62
+ options: [
63
+ RDF::CLI::Option.new(
64
+ symbol: :conclusions,
65
+ datatype: TrueClass,
66
+ control: :checkbox,
67
+ use: :optional,
68
+ on: ["--conclusions"],
69
+ description: "Exclude formulae and statements in the original dataset."),
70
+ RDF::CLI::Option.new(
71
+ symbol: :data,
72
+ datatype: TrueClass,
73
+ control: :checkbox,
74
+ use: :optional,
75
+ on: ["--data"],
76
+ description: "Only results from default graph, excluding formulae or variables."),
77
+ RDF::CLI::Option.new(
78
+ symbol: :strings,
79
+ datatype: TrueClass,
80
+ control: :checkbox,
81
+ use: :optional,
82
+ on: ["--strings"],
83
+ description: "Returns the concatenated strings from log:outputString."),
84
+ RDF::CLI::Option.new(
85
+ symbol: :think,
86
+ datatype: TrueClass,
87
+ control: :checkbox,
88
+ use: :optional,
89
+ on: ["--think"],
90
+ description: "Continuously execute until results stop growing."),
91
+ ]
92
+ },
93
+ }
94
+ end
30
95
  end
31
96
  end