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,26 @@
1
+ module RDF::N3::Algebra::Math
2
+ ##
3
+ # The object is calulated as the arc cosine value of the subject.
4
+ class ACos < RDF::N3::Algebra::ResourceOperator
5
+ NAME = :mathACos
6
+ URI = RDF::N3::Math.acos
7
+
8
+ ##
9
+ # The math:acos operator takes string or number and calculates its arc cosine.
10
+ #
11
+ # @param [RDF::Term] resource
12
+ # @param [:subject, :object] position
13
+ # @return [RDF::Term]
14
+ # @see RDF::N3::ResourceOperator#evaluate
15
+ def resolve(resource, position:)
16
+ case position
17
+ when :subject
18
+ return nil unless resource.literal?
19
+ as_literal(Math.acos(resource.as_number.object))
20
+ when :object
21
+ return nil unless resource.literal? || resource.variable?
22
+ resource
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,26 @@
1
+ module RDF::N3::Algebra::Math
2
+ ##
3
+ # The object is calulated as the inverse hyperbolic cosine value of the subject.
4
+ class ACosH < RDF::N3::Algebra::ResourceOperator
5
+ NAME = :mathACosH
6
+ URI = RDF::N3::Math.acosh
7
+
8
+ ##
9
+ # The math:acosh operator takes string or number and calculates its inverse hyperbolic cosine.
10
+ #
11
+ # @param [RDF::Term] resource
12
+ # @param [:subject, :object] position
13
+ # @return [RDF::Term]
14
+ # @see RDF::N3::ResourceOperator#evaluate
15
+ def resolve(resource, position:)
16
+ case position
17
+ when :subject
18
+ return nil unless resource.literal?
19
+ as_literal(Math.acosh(resource.as_number.object))
20
+ when :object
21
+ return nil unless resource.literal? || resource.variable?
22
+ resource
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,26 @@
1
+ module RDF::N3::Algebra::Math
2
+ ##
3
+ # The object is calulated as the arc sine value of the subject.
4
+ class ASin < RDF::N3::Algebra::ResourceOperator
5
+ NAME = :mathASin
6
+ URI = RDF::N3::Math.asin
7
+
8
+ ##
9
+ # The math:asin operator takes string or number and calculates its arc sine.
10
+ #
11
+ # @param [RDF::Term] resource
12
+ # @param [:subject, :object] position
13
+ # @return [RDF::Term]
14
+ # @see RDF::N3::ResourceOperator#evaluate
15
+ def resolve(resource, position:)
16
+ case position
17
+ when :subject
18
+ return nil unless resource.literal?
19
+ as_literal(Math.asin(resource.as_number.object))
20
+ when :object
21
+ return nil unless resource.literal? || resource.variable?
22
+ resource
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,26 @@
1
+ module RDF::N3::Algebra::Math
2
+ ##
3
+ # The object is calulated as the inverse hyperbolic sine value of the subject.
4
+ class ASinH < RDF::N3::Algebra::ResourceOperator
5
+ NAME = :mathASinH
6
+ URI = RDF::N3::Math.asinh
7
+
8
+ ##
9
+ # The math:asinh operator takes string or number and calculates its inverse hyperbolic sine.
10
+ #
11
+ # @param [RDF::Term] resource
12
+ # @param [:subject, :object] position
13
+ # @return [RDF::Term]
14
+ # @see RDF::N3::ResourceOperator#evaluate
15
+ def resolve(resource, position:)
16
+ case position
17
+ when :subject
18
+ return nil unless resource.literal?
19
+ as_literal(Math.asinh(resource.as_number.object))
20
+ when :object
21
+ return nil unless resource.literal? || resource.variable?
22
+ resource
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,26 @@
1
+ module RDF::N3::Algebra::Math
2
+ ##
3
+ # The object is calulated as the arc tangent value of the subject.
4
+ class ATan < RDF::N3::Algebra::ResourceOperator
5
+ NAME = :mathATan
6
+ URI = RDF::N3::Math.atan
7
+
8
+ ##
9
+ # The math:atan operator takes string or number and calculates its arc tangent.
10
+ #
11
+ # @param [RDF::Term] resource
12
+ # @param [:subject, :object] position
13
+ # @return [RDF::Term]
14
+ # @see RDF::N3::ResourceOperator#evaluate
15
+ def resolve(resource, position:)
16
+ case position
17
+ when :subject
18
+ return nil unless resource.literal?
19
+ as_literal(Math.atan(resource.as_number.object))
20
+ when :object
21
+ return nil unless resource.literal? || resource.variable?
22
+ resource
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,26 @@
1
+ module RDF::N3::Algebra::Math
2
+ ##
3
+ # The object is calulated as the inverse hyperbolic tangent value of the subject.
4
+ class ATanH < RDF::N3::Algebra::ResourceOperator
5
+ NAME = :mathATanH
6
+ URI = RDF::N3::Math.atanh
7
+
8
+ ##
9
+ # The math:atanh operator takes string or number and calculates its inverse hyperbolic tangent.
10
+ #
11
+ # @param [RDF::Term] resource
12
+ # @param [:subject, :object] position
13
+ # @return [RDF::Term]
14
+ # @see RDF::N3::ResourceOperator#evaluate
15
+ def resolve(resource, position:)
16
+ case position
17
+ when :subject
18
+ return nil unless resource.literal?
19
+ as_literal(Math.atanh(resource.as_number.object))
20
+ when :object
21
+ return nil unless resource.literal? || resource.variable?
22
+ resource
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,28 @@
1
+ module RDF::N3::Algebra::Math
2
+ ##
3
+ # The object is calculated as the subject upwards to a whole number.
4
+ #
5
+ # @see https://www.w3.org/TR/xpath-functions/#func-ceiling
6
+ class Ceiling < RDF::N3::Algebra::ResourceOperator
7
+ NAME = :mathCeiling
8
+ URI = RDF::N3::Math.ceiling
9
+
10
+ ##
11
+ # The math:ceiling operator takes string or number and calculates its ceiling.
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
+ as_literal(resource.as_number.ceil)
22
+ when :object
23
+ return nil unless resource.literal? || resource.variable?
24
+ resource
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,40 @@
1
+ module RDF::N3::Algebra::Math
2
+ ##
3
+ # The subject is an angle expressed in radians. The object is calulated as the cosine value of the subject.
4
+ #
5
+ # @see https://www.w3.org/TR/xpath-functions/#func-math-cos
6
+ class Cos < RDF::N3::Algebra::ResourceOperator
7
+ NAME = :mathCos
8
+ URI = RDF::N3::Math.cos
9
+
10
+ ##
11
+ # The math:cos operator takes string or number and calculates its cosine. The arc cosine of a concrete object can also calculate a variable subject.
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 resource
19
+ when RDF::Query::Variable then resource
20
+ when RDF::Literal
21
+ case position
22
+ when :subject
23
+ as_literal(Math.cos(resource.as_number.object))
24
+ when :object
25
+ as_literal(Math.acos(resource.as_number.object))
26
+ end
27
+ else
28
+ nil
29
+ end
30
+ end
31
+
32
+ ##
33
+ # Input is either the subject or object
34
+ #
35
+ # @return [RDF::Term]
36
+ def input_operand
37
+ RDF::N3::List.new(values: operands)
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,38 @@
1
+ module RDF::N3::Algebra::Math
2
+ ##
3
+ # The subject is an angle expressed in radians. The object is calulated as the hyperbolic cosine value of the subject.
4
+ class CosH < RDF::N3::Algebra::ResourceOperator
5
+ NAME = :mathCosH
6
+ URI = RDF::N3::Math.cosh
7
+
8
+ ##
9
+ # The math:cosh operator takes string or number and calculates its hyperbolic cosine. The inverse hyperbolic cosine of a concrete object can also calculate a variable subject.
10
+ #
11
+ # @param [RDF::Term] resource
12
+ # @param [:subject, :object] position
13
+ # @return [RDF::Term]
14
+ # @see RDF::N3::ResourceOperator#evaluate
15
+ def resolve(resource, position:)
16
+ case resource
17
+ when RDF::Query::Variable then resource
18
+ when RDF::Literal
19
+ case position
20
+ when :subject
21
+ as_literal(Math.cosh(resource.as_number.object))
22
+ when :object
23
+ as_literal(Math.acosh(resource.as_number.object))
24
+ end
25
+ else
26
+ nil
27
+ end
28
+ end
29
+
30
+ ##
31
+ # Input is either the subject or object
32
+ #
33
+ # @return [RDF::Term]
34
+ def input_operand
35
+ RDF::N3::List.new(values: operands)
36
+ end
37
+ end
38
+ end
@@ -1,9 +1,40 @@
1
1
  module RDF::N3::Algebra::Math
2
2
  ##
3
3
  # The subject is a pair of numbers. The object is calculated by subtracting the second number of the pair from the first.
4
- class Difference < SPARQL::Algebra::Operator::Binary
5
- include RDF::Util::Logger
6
-
4
+ #
5
+ # @example
6
+ # { ("8" "3") math:difference ?x} => { ?x :valueOf "8 - 3" } .
7
+ # { ("8") math:difference ?x } => { ?x :valueOf "8 - (error?)" } .
8
+ # { (8 3) math:difference ?x} => { ?x :valueOf "8 - 3" } .
9
+ #
10
+ # @see https://www.w3.org/TR/xpath-functions/#func-numeric-subtract
11
+ class Difference < RDF::N3::Algebra::ListOperator
7
12
  NAME = :mathDifference
13
+ URI = RDF::N3::Math.difference
14
+
15
+ ##
16
+ # The math:difference operator takes a pair of strings or numbers and calculates their difference.
17
+ #
18
+ # @param [RDF::N3::List] list
19
+ # @return [RDF::Term]
20
+ # @see RDF::N3::ListOperator#evaluate
21
+ def resolve(list)
22
+ list.to_a.map(&:as_number).reduce(&:-)
23
+ end
24
+
25
+ ##
26
+ # The list argument must be a pair of literals.
27
+ #
28
+ # @param [RDF::N3::List] list
29
+ # @return [Boolean]
30
+ # @see RDF::N3::ListOperator#validate
31
+ def validate(list)
32
+ if super && list.all?(&:literal?) && list.length == 2
33
+ true
34
+ else
35
+ log_error(NAME) {"list is not a pair of literals: #{list.to_sxp}"}
36
+ false
37
+ end
38
+ end
8
39
  end
9
40
  end
@@ -0,0 +1,54 @@
1
+ module RDF::N3::Algebra::Math
2
+ ##
3
+ # **schema**:
4
+ # `$a1 math:equalTo $a2`
5
+ #
6
+ # **summary**:
7
+ # checks equality of numbers
8
+ #
9
+ # **definition**:
10
+ # `true` if and only if `$a1` is equal to `$a2`.
11
+ # Requires both arguments to be either concrete numerals, or variables bound to a numeral.
12
+ #
13
+ # **literal domains**:
14
+ #
15
+ # * `$a1`: `xs:decimal` (or its derived types), `xs:float`, or `xs:double` (see note on type promotion, and casting from string)
16
+ # * `$a2`: `xs:decimal` (or its derived types), `xs:float`, or `xs:double` (see note on type promotion, and casting from string)
17
+ #
18
+ # @see https://www.w3.org/TR/xpath-functions/#func-numeric-equal
19
+ class EqualTo < RDF::N3::Algebra::ResourceOperator
20
+ NAME = :mathEqualTo
21
+ URI = RDF::N3::Math.equalTo
22
+
23
+ ##
24
+ # Resolves inputs as numbers.
25
+ #
26
+ # @param [RDF::Term] resource
27
+ # @param [:subject, :object] position
28
+ # @return [RDF::Term]
29
+ # @see RDF::N3::ResourceOperator#evaluate
30
+ def resolve(resource, position:)
31
+ resource.as_number if resource.term?
32
+ end
33
+
34
+ # Both subject and object are inputs.
35
+ def input_operand
36
+ RDF::N3::List.new(values: operands)
37
+ end
38
+
39
+ ##
40
+ # Returns TRUE if `term1` and `term2` are the same numeric value.
41
+ #
42
+ # @param [RDF::Term] term1
43
+ # an RDF term
44
+ # @param [RDF::Term] term2
45
+ # an RDF term
46
+ # @return [RDF::Literal::Boolean] `true` or `false`
47
+ # @raise [TypeError] if either operand is not an RDF term or operands are not comperable
48
+ #
49
+ # @see RDF::Term#==
50
+ def apply(term1, term2)
51
+ RDF::Literal(term1 == term2)
52
+ end
53
+ end
54
+ end
@@ -1,9 +1,35 @@
1
1
  module RDF::N3::Algebra::Math
2
2
  ##
3
3
  # The subject is a pair of numbers. The object is calculated by raising the first number of the power of the second.
4
- class Exponentiation < SPARQL::Algebra::Operator::Binary
5
- include RDF::Util::Logger
6
-
4
+ #
5
+ # @see https://www.w3.org/TR/xpath-functions/#func-math-exp
6
+ class Exponentiation < RDF::N3::Algebra::ListOperator
7
7
  NAME = :mathExponentiation
8
+ URI = RDF::N3::Math.exponentiation
9
+
10
+ ##
11
+ # The math:difference operator takes a pair of strings or numbers and calculates the exponent.
12
+ #
13
+ # @param [RDF::N3::List] list
14
+ # @return [RDF::Term]
15
+ # @see RDF::N3::ListOperator#evaluate
16
+ def resolve(list)
17
+ list.to_a.map(&:as_number).reduce(&:**)
18
+ end
19
+
20
+ ##
21
+ # The list argument must be a pair of literals.
22
+ #
23
+ # @param [RDF::N3::List] list
24
+ # @return [Boolean]
25
+ # @see RDF::N3::ListOperator#validate
26
+ def validate(list)
27
+ if super && list.all?(&:literal?) && list.length == 2
28
+ true
29
+ else
30
+ log_error(NAME) {"list is not a pair of literals: #{list.to_sxp}"}
31
+ false
32
+ end
33
+ end
8
34
  end
9
35
  end
@@ -0,0 +1,28 @@
1
+ module RDF::N3::Algebra::Math
2
+ ##
3
+ # The object is calculated as the subject downwards to a whole number.
4
+ #
5
+ # @see https://www.w3.org/TR/xpath-functions/#func-floor
6
+ class Floor < RDF::N3::Algebra::ResourceOperator
7
+ NAME = :mathFloor
8
+ URI = RDF::N3::Math.floor
9
+
10
+ ##
11
+ # The math:floor operator takes string or number and calculates its floor.
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
+ RDF::Literal(resource.as_number.floor)
22
+ when :object
23
+ return nil unless resource.literal? || resource.variable?
24
+ resource
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,41 @@
1
+ module RDF::N3::Algebra::Math
2
+ ##
3
+ # True iff the subject is a string representation of a number which is greater than the number of which the object is a string representation.
4
+ #
5
+ # @see https://www.w3.org/TR/xpath-functions/#func-numeric-greater-than
6
+ class GreaterThan < RDF::N3::Algebra::ResourceOperator
7
+ NAME = :mathGreaterThan
8
+ URI = RDF::N3::Math.greaterThan
9
+
10
+ ##
11
+ # Resolves inputs as numbers.
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
+ resource.as_number if resource.term?
19
+ end
20
+
21
+ # Both subject and object are inputs.
22
+ def input_operand
23
+ RDF::N3::List.new(values: operands)
24
+ end
25
+
26
+ ##
27
+ # Returns TRUE if `term1` is greater than `term2`.
28
+ #
29
+ # @param [RDF::Term] term1
30
+ # an RDF term
31
+ # @param [RDF::Term] term2
32
+ # an RDF term
33
+ # @return [RDF::Literal::Boolean] `true` or `false`
34
+ # @raise [TypeError] if either operand is not an RDF term or operands are not comperable
35
+ #
36
+ # @see RDF::Term#==
37
+ def apply(term1, term2)
38
+ RDF::Literal(term1 > term2)
39
+ end
40
+ end
41
+ end