Skip to content

Commit 5cb934e

Browse files
committed
Added sugar for data property restrictions, and fixed some bugs with data ranges.
1 parent 7ef3c26 commit 5cb934e

File tree

3 files changed

+52
-9
lines changed

3 files changed

+52
-9
lines changed

core/src/main/scala/uk/co/turingatemyhamster/owl2/ast/DataPropertyRestrictionsModuleAst.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ trait DataPropertyRestrictionsModuleImpl extends owl2.DataPropertyRestrictionsMo
2121

2222
}
2323

24-
case class DataSomeValuesFrom(dataPropertyExpression: DataPropertyExpression, arity: BigInt) extends ClassExpression
24+
case class DataSomeValuesFrom(dataPropertyExpression: List[DataPropertyExpression], dataRange: DataRange, arity: BigInt = BigInt(1)) extends ClassExpression
2525

26-
case class DataAllValuesFrom(dataPropertyExpression: DataPropertyExpression, arity: BigInt) extends ClassExpression
26+
case class DataAllValuesFrom(dataPropertyExpression: List[DataPropertyExpression], dataRange: DataRange, arity: BigInt = BigInt(1)) extends ClassExpression
2727

2828
case class DataHasValue(dataPropertyExpression: DataPropertyExpression, literal: Literal) extends ClassExpression

core/src/main/scala/uk/co/turingatemyhamster/owl2/ast/DataRangesModuleAst.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ case class DataUnionOf(arity: BigInt = BigInt(1), dataRanges: List[DataRange]) e
3636

3737
case class DataOneOf(arity: BigInt = BigInt(1), literals: List[Literal]) extends DataRange
3838

39-
case class DatatypeRestriction(arity: BigInt = BigInt(1), datatype: Datatype) extends DataRange
39+
case class DatatypeRestriction(arity: BigInt = BigInt(1), datatype: Datatype, restrictions: List[FacetRestriction]) extends DataRange
4040

4141
// 2..* dataRanges
4242
case class DataIntersectionOf(arity: BigInt = BigInt(1), dataRanges: List[DataRange]) extends DataRange

core/src/main/scala/uk/co/turingatemyhamster/owl2/examples/UsingAst.scala

+49-6
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ object UsingAst {
3636
def === (c: Int): ===[I] = examples.===(_i, BigInt(c))
3737

3838
def (c: Int): [I] = examples.(_i, BigInt(c))
39+
40+
def ^^[J](j: J)(implicit iString: I => String, jDatatype: J => Datatype): TypedLiteral = TypedLiteral(_i, j)
41+
42+
def | [J](j: J)(implicit iDT: I => Datatype, jFR: J => FacetRestriction): DatatypeRestriction =
43+
DatatypeRestriction(datatype = _i, restrictions = j::Nil)
3944
}
4045
}
4146

@@ -64,11 +69,19 @@ object Triple {
6469
AnnotationAssertion(Nil, t.sub, t.pred, t.obj)
6570

6671
implicit def toObjectPropertyAssertion[Sub, Pred, Obj](t: Triple[Sub, Pred, Obj]
67-
)(implicit
68-
subIndividual: Sub => Individual,
69-
predPE: Pred => ObjectPropertyExpression,
70-
objIndividual: Obj => Individual): ObjectPropertyAssertion =
71-
ObjectPropertyAssertion(Nil, t.sub, t.pred, t.obj)
72+
)(implicit
73+
subIndividual: Sub => Individual,
74+
predPE: Pred => ObjectPropertyExpression,
75+
objIndividual: Obj => Individual): ObjectPropertyAssertion =
76+
ObjectPropertyAssertion(Nil, t.sub, t.pred, t.obj)
77+
78+
implicit def toDataPropertyAssertion[Sub, Pred, Obj](t: Triple[Sub, Pred, Obj]
79+
)(implicit
80+
subIndividual: Sub => Individual,
81+
predPE: Pred => DataPropertyExpression,
82+
objLit: Obj => Literal): DataPropertyAssertion =
83+
DataPropertyAssertion(Nil, t.sub, t.pred, t.obj)
84+
7285
}
7386

7487
case class Inverse[P](p: P) {
@@ -145,7 +158,12 @@ case object ∃ {
145158
implicit def someObjectSomeValuesFrom[P, V](some: [P, V])(implicit
146159
pPE: P => ObjectPropertyExpression,
147160
vCE: V => ClassExpression): ObjectSomeValuesFrom =
148-
ObjectSomeValuesFrom(some.p, some.v)
161+
ObjectSomeValuesFrom(some.p, some.v)
162+
163+
implicit def someDataSomeValuesFrom[P, V](some: [P, V])(implicit
164+
pPE: P => DataPropertyExpression,
165+
vDR: V => DataRange): DataSomeValuesFrom =
166+
DataSomeValuesFrom(some.p::Nil, some.v)
149167
}
150168

151169
case class [P, V](p: P, v: V)
@@ -155,6 +173,11 @@ case object ∀ {
155173
pPE: P => ObjectPropertyExpression,
156174
vCE: V => ClassExpression): ObjectAllValuesFrom =
157175
ObjectAllValuesFrom(all.p, all.v)
176+
177+
implicit def allDataValuesFrom[P, V](all: [P, V])(implicit
178+
pPE: P => DataPropertyExpression,
179+
vDR: V => DataRange): DataAllValuesFrom =
180+
DataAllValuesFrom(all.p::Nil, all.v)
158181
}
159182

160183
case class [P, V](p: P, v: V)
@@ -164,6 +187,11 @@ object ∈ {
164187
pPE: P => ObjectPropertyExpression,
165188
vI: V => Individual): ObjectHasValue =
166189
ObjectHasValue(pv.p, pv.v)
190+
191+
implicit def toDataHasValue[P, V](pv: [P, V])(implicit
192+
pPE: P => DataPropertyExpression,
193+
vI: V => Literal): DataHasValue =
194+
DataHasValue(pv.p, pv.v)
167195
}
168196

169197
case class [P](p: P, c: BigInt)
@@ -348,6 +376,21 @@ class UsingAst {
348376
ObjectMinCardinality(objectPropertyExpression = "a" -> "hasPet", cardinality = BigInt(1))
349377
"a" -> "hasPet" 1 : ObjectMinCardinality
350378

379+
DataPropertyAssertion(Nil, "a" -> "Meg", "a" -> "hasAge", "17"^^("xsd" -> "integer"))
380+
("a" -> "Meg") --- ("a" -> "hasAge") --> ("17"^^("xsd" -> "integer")) : DataPropertyAssertion
381+
382+
DataSomeValuesFrom(
383+
("a" -> "hasAge")::Nil,
384+
DatatypeRestriction(
385+
BigInt(1),
386+
"xsd" -> "integer",
387+
FacetRestriction("xsd" -> "maxExclusive", "20"^^("xsd" -> "integer"))::Nil),
388+
BigInt(1))
389+
390+
("a" -> "hasAge", "xsd" -> "integer" | "xsd" -> "maxExclusive" -> ("20"^^("xsd" -> "integer"))) : DataSomeValuesFrom
391+
("a" -> "hasZIP", "xsd" -> "integer") : DataAllValuesFrom
392+
("a" -> "hasAge", "17"^^("xsd" -> "integer")) : DataHasValue
393+
351394
SubObjectPropertyOf(Nil, "a" -> "hasDog", ("a" -> "hasPet" : ObjectPropertyExpression) :: Nil)
352395
ObjectPropertyAssertion(Nil, "a" -> "Peter", "a" -> "hasDog", "a" -> "Brian")
353396
ObjectPropertyAssertion(Nil, "a" -> "Peter", "a" -> "hasPet", "a" -> "Brian")

0 commit comments

Comments
 (0)