Skip to content

Commit d7da2a5

Browse files
committed
GH-3507: RDFS testing/wrapping/benchmark framework. Fixed literals-in-subject inferences.
1 parent b7f7774 commit d7da2a5

34 files changed

+1634
-206
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,7 @@ hs_err_*
4242

4343
# Fuseki file area
4444
run/
45+
46+
# Benchmark JSON results
47+
jena-benchmarks/jena-benchmarks-jmh/*.json
48+

jena-arq/pom.xml

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
<dependency>
6262
<groupId>com.google.code.gson</groupId>
6363
<artifactId>gson</artifactId>
64-
</dependency>
64+
</dependency>
6565

6666
<dependency>
6767
<groupId>org.slf4j</groupId>
@@ -87,12 +87,12 @@
8787
<artifactId>jakarta.json</artifactId>
8888
</dependency>
8989
<!-- End Titanium JSON-LD 1.1 -->
90-
90+
9191
<dependency>
9292
<groupId>com.google.protobuf</groupId>
9393
<artifactId>protobuf-java</artifactId>
9494
</dependency>
95-
95+
9696
<dependency>
9797
<groupId>org.apache.thrift</groupId>
9898
<artifactId>libthrift</artifactId>
@@ -140,6 +140,11 @@
140140
<scope>test</scope>
141141
</dependency>
142142

143+
<dependency>
144+
<groupId>org.apache.commons</groupId>
145+
<artifactId>commons-math4-legacy</artifactId>
146+
<scope>test</scope>
147+
</dependency>
143148
</dependencies>
144149

145150
<build>
@@ -155,7 +160,7 @@
155160
<groupId>org.apache.maven.plugins</groupId>
156161
<artifactId>maven-resources-plugin</artifactId>
157162
</plugin>
158-
163+
159164
<plugin>
160165
<groupId>org.apache.maven.plugins</groupId>
161166
<artifactId>maven-surefire-plugin</artifactId>
@@ -188,11 +193,11 @@
188193
<plugin>
189194
<groupId>org.apache.maven.plugins</groupId>
190195
<artifactId>maven-source-plugin</artifactId>
191-
<executions>
196+
<executions>
192197
<execution>
193-
<id>attach-sources-test</id>
198+
<id>attach-sources-test</id>
194199
<goals>
195-
<goal>test-jar-no-fork</goal>
200+
<goal>test-jar-no-fork</goal>
196201
</goals>
197202
</execution>
198203
</executions>

jena-arq/src/main/java/org/apache/jena/rdfs/DatasetGraphRDFS.java

Lines changed: 4 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -18,134 +18,22 @@
1818

1919
package org.apache.jena.rdfs;
2020

21-
import static org.apache.jena.atlas.iterator.Iter.iter;
22-
23-
import java.util.Iterator;
24-
25-
import org.apache.jena.atlas.iterator.Iter;
26-
import org.apache.jena.graph.Graph;
27-
import org.apache.jena.graph.Node;
21+
import org.apache.jena.rdfs.engine.DatasetGraphWithGraphTransform;
2822
import org.apache.jena.sparql.core.DatasetGraph;
29-
import org.apache.jena.sparql.core.DatasetGraphWrapper;
3023
import org.apache.jena.sparql.core.DatasetGraphWrapperView;
31-
import org.apache.jena.sparql.core.Quad;
3224
import org.apache.jena.sparql.util.Context;
3325

34-
public class DatasetGraphRDFS extends DatasetGraphWrapper implements DatasetGraphWrapperView {
26+
public class DatasetGraphRDFS extends DatasetGraphWithGraphTransform implements DatasetGraphWrapperView {
3527
// Do not unwrap for query execution.
36-
3728
private final SetupRDFS setup;
3829

3930
public DatasetGraphRDFS(DatasetGraph dsg, SetupRDFS setup) {
40-
super(dsg);
31+
super(dsg, g -> new GraphRDFS(g, setup));
4132
this.setup = setup;
4233
}
4334

4435
public DatasetGraphRDFS(DatasetGraph dsg, SetupRDFS setup, Context cxt) {
45-
super(dsg, cxt);
36+
super(dsg, cxt, g -> new GraphRDFS(g, setup));
4637
this.setup = setup;
4738
}
48-
49-
// Graph-centric access.
50-
@Override
51-
public Graph getDefaultGraph() {
52-
Graph base = getG().getDefaultGraph();
53-
return new GraphRDFS(base, setup);
54-
}
55-
56-
@Override
57-
public Graph getUnionGraph() {
58-
Graph base = getG().getUnionGraph();
59-
return new GraphRDFS(base, setup);
60-
}
61-
62-
@Override
63-
public Graph getGraph(Node graphNode) {
64-
Graph base = getG().getGraph(graphNode);
65-
if ( base == null )
66-
return null;
67-
return new GraphRDFS(base, setup);
68-
}
69-
70-
@Override
71-
public Iterator<Quad> find()
72-
{ return find(Node.ANY, Node.ANY, Node.ANY, Node.ANY); }
73-
74-
// Quad-centric access
75-
@Override
76-
public Iterator<Quad> find(Quad quad) {
77-
return find(quad.getGraph(), quad.getSubject(), quad.getPredicate(), quad.getObject());
78-
}
79-
80-
@Override
81-
public Iterator<Quad> find(Node g, Node s, Node p, Node o) {
82-
Iterator<Quad> iter = findInf(g, s, p, o);
83-
if ( iter == null )
84-
return Iter.nullIterator();
85-
return iter;
86-
}
87-
88-
// private Iterator<Quad> findInf(Node g, Node s, Node p, Node o) {
89-
// // Puts in the graph name for the quad base don g even if g is ANY or null.
90-
// MatchRDFS<Node, Quad> infMatcher = new InfFindQuad(setup, g, getR());
91-
// Stream<Quad> quads = infMatcher.match(s, p, o);
92-
// Iterator<Quad> iter = quads.iterator();
93-
// iter = Iter.onClose(iter, ()->quads.close());
94-
// return iter;
95-
// }
96-
97-
/**
98-
* Find, graph by graph.
99-
*/
100-
private Iterator<Quad> findInf(Node g, Node s, Node p, Node o) {
101-
if ( g != null && g.isConcrete() ) {
102-
// Includes the union graph case.
103-
return findOneGraphInf(g, s, p, o);
104-
}
105-
// Wildcard. Do each graph in-term.
106-
// This ensures the graph node of the quad corresponds to where the inference came from.
107-
Iter<Quad> iter1 = findOneGraphInf(Quad.defaultGraphIRI, s, p, o);
108-
Iterator<Quad> iter2 = findAllNamedGraphInf(s, p, o);
109-
return iter1.append(iter2);
110-
}
111-
112-
// All named graphs, with inference. Quads refer to the name graph they were caused by.
113-
private Iterator<Quad> findAllNamedGraphInf(Node s, Node p, Node o) {
114-
return Iter.flatMap(listGraphNodes(), gn -> findOneGraphInf(gn, s, p, o));
115-
}
116-
117-
// Single graph (inc. union graph). Quads refer to the name graph they were caused by.
118-
private Iter<Quad> findOneGraphInf(Node g, Node s, Node p, Node o) {
119-
if ( ! g.isConcrete() )
120-
throw new IllegalStateException();
121-
// f ( Quad.isUnionGraph(g) ) {}
122-
// Specific named graph.
123-
return iter(getGraph(g).find(s,p,o)).map(t->Quad.create(g, t));
124-
}
125-
126-
@Override
127-
public Iterator<Quad> findNG(Node g, Node s, Node p, Node o) {
128-
if ( Quad.isDefaultGraph(g) )
129-
throw new IllegalArgumentException("Default graph in findNG call");
130-
if ( g == null )
131-
g = Node.ANY;
132-
if ( g == Node.ANY )
133-
return findAllNamedGraphInf(s, p, o);
134-
// Same as specific named graph - we return quads in the union graph.
135-
// if ( Quad.isUnionGraph(g) ) {}
136-
return findOneGraphInf(g, s, p, o);
137-
}
138-
139-
@Override
140-
public boolean contains(Quad quad)
141-
{ return contains(quad.getGraph(), quad.getSubject(), quad.getPredicate(), quad.getObject()); }
142-
143-
@Override
144-
public boolean contains(Node g, Node s, Node p, Node o) {
145-
// Go through the inference machinery.
146-
Iterator<Quad> iter = find(g, s, p, o);
147-
try {
148-
return iter.hasNext();
149-
} finally { Iter.close(iter); }
150-
}
15139
}

jena-arq/src/main/java/org/apache/jena/rdfs/GraphRDFS.java

Lines changed: 3 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -18,73 +18,20 @@
1818

1919
package org.apache.jena.rdfs;
2020

21-
import java.util.stream.Stream;
22-
2321
import org.apache.jena.graph.Graph;
2422
import org.apache.jena.graph.Node;
25-
import org.apache.jena.graph.Triple;
23+
import org.apache.jena.rdfs.engine.GraphMatch;
2624
import org.apache.jena.rdfs.engine.InfFindTriple;
27-
import org.apache.jena.rdfs.engine.MatchRDFS;
2825
import org.apache.jena.rdfs.setup.ConfigRDFS;
29-
import org.apache.jena.sparql.graph.GraphWrapper;
30-
import org.apache.jena.util.iterator.ExtendedIterator;
31-
import org.apache.jena.util.iterator.WrappedIterator;
3226

3327
/**
3428
* RDFS graph over a base graph.
3529
*/
36-
public class GraphRDFS extends GraphWrapper {
37-
private final MatchRDFS<Node, Triple> source;
30+
public class GraphRDFS extends GraphMatch {
3831
private final ConfigRDFS<Node> setup;
3932

4033
public GraphRDFS(Graph graph, ConfigRDFS<Node> setup) {
41-
super(graph);
34+
super(graph, new InfFindTriple(setup, graph));
4235
this.setup = setup;
43-
this.source = new InfFindTriple(setup, graph);
44-
}
45-
46-
@Override
47-
public ExtendedIterator<Triple> find(Triple m) {
48-
return find(m.getSubject(), m.getPredicate(), m.getObject());
49-
}
50-
51-
@Override
52-
public ExtendedIterator<Triple> find(Node s, Node p, Node o) {
53-
Stream<Triple> stream = source.match(s, p, o);
54-
ExtendedIterator<Triple> iter = WrappedIterator.ofStream(stream);
55-
return iter;
56-
}
57-
58-
@Override
59-
public Stream<Triple> stream(Node s, Node p, Node o) {
60-
return source.match(s, p, o);
61-
}
62-
63-
@Override
64-
public boolean contains(Node s, Node p, Node o) {
65-
// Must go via find()-like functionality.
66-
ExtendedIterator<Triple> iter = find(s, p, o);
67-
try {
68-
return iter.hasNext();
69-
} finally { iter.close(); }
70-
}
71-
72-
@Override
73-
public boolean contains(Triple t) {
74-
return contains(t.getSubject(), t.getPredicate(), t.getObject());
75-
}
76-
77-
@Override
78-
public int size() {
79-
// Report the size of the underlying graph.
80-
// Even better, don't ask.
81-
return super.size();
82-
}
83-
84-
@Override
85-
public boolean dependsOn(Graph other) {
86-
if ( other == super.get() )
87-
return true;
88-
return super.dependsOn(other);
8936
}
9037
}

jena-arq/src/main/java/org/apache/jena/rdfs/RDFSFactory.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,13 @@ public static DatasetGraph datasetRDFS(DatasetGraph data, SetupRDFS setup) {
5656
/** Create an RDFS inference dataset. */
5757
public static DatasetGraph datasetRDFS(DatasetGraph data, Graph vocab ) {
5858
SetupRDFS setup = setupRDFS(vocab);
59-
return new DatasetGraphRDFS(data, setup);
59+
return datasetRDFS(data, setup);
6060
}
6161

6262
/** Create an RDFS inference dataset. */
6363
public static Dataset datasetRDFS(Dataset data, Graph vocab ) {
6464
SetupRDFS setup = setupRDFS(vocab);
65-
return DatasetFactory.wrap(new DatasetGraphRDFS(data.asDatasetGraph(), setup));
65+
return DatasetFactory.wrap(datasetRDFS(data.asDatasetGraph(), setup));
6666
}
6767

6868
/** Create an {@link SetupRDFS} */

jena-arq/src/main/java/org/apache/jena/rdfs/assembler/DatasetRDFSAssembler.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import org.apache.jena.assembler.exceptions.AssemblerException;
2727
import org.apache.jena.graph.Graph;
2828
import org.apache.jena.rdf.model.Resource;
29-
import org.apache.jena.rdfs.DatasetGraphRDFS;
3029
import org.apache.jena.rdfs.RDFSFactory;
3130
import org.apache.jena.rdfs.SetupRDFS;
3231
import org.apache.jena.riot.RDFDataMgr;
@@ -50,15 +49,14 @@ public Map<String, DatasetGraph> pool() {
5049
/**
5150
* <pre>
5251
* &lt;#rdfsDS&gt; rdf:type ja:DatasetRDFS ;
53-
* ja:rdfs "vocab.ttl";
52+
* ja:rdfsSchema "vocab.ttl";
5453
* ja:dataset &lt;#baseDS&gt; ;
5554
* .
5655
*
5756
* &lt;#baseDS&gt; rdf:type ja:MemoryDataset ;
5857
* ja:name "TIM database" # optional: this is need if the base database is accessed directly.
5958
* ja:data "data1.trig";
6059
* ## ja:data "data2.trig";
61-
*
6260
* .
6361
* </pre>
6462
*/
@@ -76,7 +74,7 @@ public DatasetGraph createDataset(Assembler a, Resource root) {
7674

7775
Graph schema = RDFDataMgr.loadGraph(schemaFile);
7876
SetupRDFS setup = RDFSFactory.setupRDFS(schema);
79-
DatasetGraph dsg = new DatasetGraphRDFS(base, setup);
77+
DatasetGraph dsg = RDFSFactory.datasetRDFS(base, setup);
8078
AssemblerUtils.mergeContext(root, dsg.getContext());
8179
return dsg;
8280
}

jena-arq/src/main/java/org/apache/jena/rdfs/assembler/GraphRDFSAssembler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public Object open(Assembler a, Resource root, Mode mode) {
4848
/**
4949
* <pre>
5050
* &lt;#rdfsGraph&gt; rdf:type ja:GraphRDFS ;
51-
* ja:rdfs "vocab.ttl";
51+
* ja:rdfsSchema "vocab.ttl";
5252
* ja:graph &lt;#baseGraph&gt; ;
5353
* .
5454
*

jena-arq/src/main/java/org/apache/jena/rdfs/engine/ApplyRDFS.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,12 @@ final private void range(X s, X p, X o, Output<X> out) {
129129
return;
130130
}
131131
Set<X> x = setup.getRange(p);
132-
x.forEach(c -> {
133-
derive(o, rdfType, c, out);
134-
subClass(o, rdfType, c, out);
135-
});
132+
if (!mapper.isLiteral(o)) {
133+
x.forEach(c -> {
134+
derive(o, rdfType, c, out);
135+
subClass(o, rdfType, c, out);
136+
});
137+
}
136138
}
137139
}
138140

0 commit comments

Comments
 (0)