-
Notifications
You must be signed in to change notification settings - Fork 3
/
prune.dl
40 lines (32 loc) · 1.87 KB
/
prune.dl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#define RDF_TYPE "<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>"
#define RDFS_SUBCLASS_OF "<http://www.w3.org/2000/01/rdf-schema#subClassOf>"
#define RDFS_SUBPROPERTY_OF "<http://www.w3.org/2000/01/rdf-schema#subPropertyOf>"
#define OWL_TRANSITIVE_PROPERTY "<http://www.w3.org/2002/07/owl#TransitiveProperty>"
.type IRI <: symbol
.type BlankNode <: symbol
.type Literal <: symbol
.type Node = IRI | BlankNode
.type NodeOrLiteral = Node | Literal
.decl rdf(s: Node, p: IRI, o: NodeOrLiteral)
.decl ontrdf(s: Node, p: IRI, o: NodeOrLiteral)
.decl transitive(prop: Node)
.decl equivalent(x: Node, y: Node)
.decl subClassOf(sub: Node, super: Node)
.decl subPropertyOf(sub: Node, super: Node)
.decl redundant(s: Node, p: IRI, o: NodeOrLiteral)
.decl nonredundant(s: Node, p: IRI, o: NodeOrLiteral, dot: symbol)
equivalent(x, y) :- rdf(x, RDFS_SUBCLASS_OF, y), x != y, rdf(y, RDFS_SUBCLASS_OF, x).
subClassOf(sub, as(super, Node)) :- rdf(sub, RDFS_SUBCLASS_OF, super), sub != super, !equivalent(sub, super).
transitive(prop) :- ontrdf(prop, RDF_TYPE, OWL_TRANSITIVE_PROPERTY).
subPropertyOf(sub, as(super, Node)) :- ontrdf(sub, RDFS_SUBPROPERTY_OF, super), sub != super.
subPropertyOf(sub, as(supersuper, Node)) :- subPropertyOf(sub, super), ontrdf(super, RDFS_SUBPROPERTY_OF, supersuper), super != supersuper, sub != supersuper.
redundant(s, p, o) :- rdf(s, p, other), subClassOf(other, o), rdf(s, p, o).
redundant(s, p, o) :- rdf(s, p, o), subClassOf(s, other), rdf(other, p, o).
redundant(s, p, o) :- rdf(s, p, o), transitive(p), rdf(s, p, other), other != o, rdf(other, p, o).
redundant(s, p, o) :- rdf(s, p, o), subPropertyOf(sub, p), rdf(s, sub, o).
redundant(s, RDFS_SUBCLASS_OF, s) :- rdf(s, RDFS_SUBCLASS_OF, s).
nonredundant(s, p, o, ".") :- rdf(s, p, o), !redundant(s, p, o).
// sed 's/ /\t/' <ontology.nt | sed 's/ /\t/' | sed 's/ \.$//' >ontrdf.facts
.input rdf
.input ontrdf
.output nonredundant