-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Jan Robert <[email protected]> Co-authored-by: Yalz <[email protected]> Co-authored-by: Ranko Orlic <[email protected]>
- Loading branch information
Showing
92 changed files
with
692 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
ldi-core/ldes-client/tree-node-fetcher/src/main/java/org/apache/jena/graph/GraphExtract.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.jena.graph; | ||
|
||
import org.apache.jena.util.CollectionFactory; | ||
|
||
import java.util.Iterator; | ||
import java.util.Set; | ||
|
||
/** | ||
GraphExtract offers a very simple recursive extraction of a subgraph with a | ||
specified root in some supergraph. The recursion is terminated by triples | ||
that satisfy some supplied boundary condition. | ||
*/ | ||
public class GraphExtract { | ||
protected final TripleBoundary b; | ||
|
||
public GraphExtract(TripleBoundary b) { | ||
this.b = b; | ||
} | ||
|
||
/** | ||
Answer a new graph which is the reachable subgraph from <code>node</code> | ||
in <code>graph</code> with the terminating condition given by the | ||
TripleBoundary passed to the constructor. | ||
*/ | ||
public Graph extract(Node node, Graph graph) { | ||
return extractInto(GraphMemFactory.createGraphMem(), node, graph); | ||
} | ||
|
||
/** | ||
Answer the graph <code>toUpdate</code> augmented with the sub-graph of | ||
<code>extractFrom</code> reachable from <code>root</code> bounded | ||
by this instance's TripleBoundary. | ||
*/ | ||
public Graph extractInto(Graph toUpdate, Node root, Graph extractFrom) { | ||
new Extraction(b, toUpdate, extractFrom).extractInto(root); | ||
return toUpdate; | ||
} | ||
|
||
/** | ||
This is the class that does all the work, in the established context of the | ||
source and destination graphs, the TripleBoundary that determines the | ||
limits of the extraction, and a local set <code>active</code> of nodes | ||
already seen and hence not to be re-processed. | ||
*/ | ||
protected static class Extraction { | ||
protected Graph toUpdate; | ||
protected Graph extractFrom; | ||
protected Set<Node> active; | ||
protected TripleBoundary b; | ||
|
||
Extraction(TripleBoundary b, Graph toUpdate, Graph extractFrom) { | ||
this.toUpdate = toUpdate; | ||
this.extractFrom = extractFrom; | ||
this.active = CollectionFactory.createHashedSet(); | ||
this.b = b; | ||
} | ||
|
||
public void extractInto(Node root) { | ||
active.add(root); | ||
Iterator<Triple> it = extractFrom.find(root, Node.ANY, Node.ANY); | ||
while (it.hasNext()) { | ||
Triple t = it.next(); | ||
Node subRoot = t.getObject(); | ||
toUpdate.add(t); | ||
if (!(active.contains(subRoot) || b.stopAt(t))) extractInto(subRoot); | ||
} | ||
} | ||
} | ||
|
||
|
||
} |
42 changes: 42 additions & 0 deletions
42
...ore/ldes-client/tree-node-fetcher/src/main/java/org/apache/jena/graph/TripleBoundary.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.jena.graph; | ||
|
||
/** | ||
An interface for expressing a stopping condition on triples, such as in | ||
sub-graph extraction. | ||
*/ | ||
public interface TripleBoundary { | ||
/** | ||
Answer true if this triple is a stopping triple, and whatever search is using | ||
this interface should proceed no further. | ||
*/ | ||
boolean stopAt(Triple t); | ||
|
||
/** | ||
A TripleBoundary without limits - stopAt always returns false. | ||
*/ | ||
TripleBoundary stopNowhere = t -> false; | ||
|
||
/** | ||
A TripleBoundary that stops at triples with anonymous objects. | ||
*/ | ||
TripleBoundary stopAtAnonObject = t -> t.getObject().isBlank(); | ||
|
||
} |
67 changes: 67 additions & 0 deletions
67
...e/ldes-client/tree-node-fetcher/src/main/java/org/apache/jena/rdf/model/ModelExtract.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.jena.rdf.model; | ||
|
||
import org.apache.jena.graph.Graph; | ||
import org.apache.jena.graph.GraphExtract; | ||
import org.apache.jena.graph.TripleBoundary; | ||
|
||
/** | ||
ModelExtract - a wrapper for GraphExtract, allowing rooted sub-models to be | ||
extracted from other models with some boundary condition. | ||
*/ | ||
public class ModelExtract { | ||
/** | ||
The statement boundary used to bound the extraction. | ||
*/ | ||
protected StatementBoundary boundary; | ||
|
||
/** | ||
Initialise this ModelExtract with a boundary condition. | ||
*/ | ||
public ModelExtract(StatementBoundary b) { | ||
boundary = b; | ||
} | ||
|
||
/** | ||
Answer the rooted sub-model. | ||
*/ | ||
public Model extract(Resource r, Model s) { | ||
return extractInto(ModelFactory.createDefaultModel(), r, s); | ||
} | ||
|
||
/** | ||
Answer <code>model</code> after updating it with the sub-graph of | ||
<code>s</code> rooted at <code>r</code>, bounded by this instances | ||
<code>boundary</code>. | ||
*/ | ||
public Model extractInto(Model model, Resource r, Model s) { | ||
TripleBoundary tb = boundary.asTripleBoundary(s); | ||
Graph g = getGraphExtract(tb).extractInto(model.getGraph(), r.asNode(), s.getGraph()); | ||
return ModelFactory.createModelForGraph(g); | ||
} | ||
|
||
/** | ||
Answer a GraphExtract initialised with <code>tb</code>; extension point | ||
for sub-classes (specifically TestModelExtract's mocks). | ||
*/ | ||
protected GraphExtract getGraphExtract(TripleBoundary tb) { | ||
return new GraphExtract(tb); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
...s-client/tree-node-fetcher/src/main/java/org/apache/jena/rdf/model/StatementBoundary.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.jena.rdf.model; | ||
|
||
import org.apache.jena.graph.TripleBoundary; | ||
|
||
/** | ||
An interface for expressing search boundaries in terms of bounding statements. | ||
*/ | ||
|
||
public interface StatementBoundary { | ||
/** | ||
Answer true if this statement is a boundary of the search. | ||
*/ | ||
boolean stopAt(Statement s); | ||
|
||
/** | ||
Answer a TripleBoundary corresponding to this StatementBoundary, | ||
where Triples may be converted to Statements using <code>m</code>. | ||
*/ | ||
TripleBoundary asTripleBoundary(Model m); | ||
} |
Oops, something went wrong.