本文整理汇总了Java中org.openrdf.model.Model.filter方法的典型用法代码示例。如果您正苦于以下问题:Java Model.filter方法的具体用法?Java Model.filter怎么用?Java Model.filter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.openrdf.model.Model
的用法示例。
在下文中一共展示了Model.filter方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: compare
import org.openrdf.model.Model; //导入方法依赖的package包/类
private void compare( String label, Model expected, Model test, Resource s,
URI p, Value o ) {
Model exp = new LinkedHashModel( expected.filter( s, p, o ) );
Model tst = new LinkedHashModel( test.filter( s, p, o ) );
assertEquals( label + " size mismatch", exp.size(), tst.size() );
assertEquals( label + " predicates mismatch", exp.predicates(), tst.predicates() );
assertEquals( label + " subjects mismatch", exp.subjects(), tst.subjects() );
assertEquals( label + " subjects mismatch", exp.objects(), tst.objects() );
}
示例2: exportAllRelationships
import org.openrdf.model.Model; //导入方法依赖的package包/类
public void exportAllRelationships( Collection<URI> subjectTypes, ImportData data ) {
StructureManager sm = StructureManagerFactory.getStructureManager( engine );
for ( URI subtype : subjectTypes ) {
Model m = sm.getLinksBetween( subtype, Constants.ANYNODE );
for ( Statement s : m.filter( subtype, null, null ) ) {
exportOneRelationship( URI.class.cast( s.getSubject() ),
s.getPredicate(),
URI.class.cast( s.getObject() ), data );
}
}
}
示例3: extractMarkables
import org.openrdf.model.Model; //导入方法依赖的package包/类
private static List<Markable> extractMarkables(final List<Term> terms, final Model model,
final Map<Object, String> colorMap) {
final int[] offsets = new int[terms.size()];
for (int i = 0; i < terms.size(); ++i) {
offsets[i] = terms.get(i).getOffset();
}
final List<Markable> markables = Lists.newArrayList();
for (final Statement stmt : model.filter(null, GAF.DENOTED_BY, null)) {
final Resource instance = stmt.getSubject();
final String color = select(colorMap,
model.filter(instance, RDF.TYPE, null).objects(), null);
if (stmt.getObject() instanceof URI && color != null) {
final URI mentionURI = (URI) stmt.getObject();
final String name = mentionURI.getLocalName();
if (name.indexOf(';') < 0) {
final int index = name.indexOf(',');
final int start = Integer.parseInt(name.substring(5, index));
final int end = Integer.parseInt(name.substring(index + 1));
final int s = Arrays.binarySearch(offsets, start);
if (s >= 0) {
int e = s;
while (e < offsets.length && offsets[e] < end) {
++e;
}
markables.add(new Markable(ImmutableList.copyOf(terms.subList(s, e)),
color));
}
}
}
}
return markables;
}
示例4: getTopObject
import org.openrdf.model.Model; //导入方法依赖的package包/类
private Model getTopObject(final InferredOWLOntologyID nextArtifact, final Model artifactDetails)
throws PoddClientException
{
return artifactDetails.filter(
artifactDetails.filter(nextArtifact.getOntologyIRI().toOpenRDFURI(), PODD.PODD_BASE_HAS_TOP_OBJECT,
null).objectURI(), null, null);
}
示例5: getInstances
import org.openrdf.model.Model; //导入方法依赖的package包/类
public static Model getInstances( URI subtype, URI predtype, URI objtype,
Collection<URI> propsToInclude, IEngine engine ) {
// round one: get the relationships themselves
String query = "CONSTRUCT { ?s ?p ?o } WHERE {\n"
+ " ?s a|rdfs:subClassOf+ ?subtype .\n"
+ " ?o a|rdfs:subClassOf+ ?objtype .\n"
+ " ?p a|rdfs:subPropertyOf+ ?predtype .\n"
+ " FILTER( ?s != ?subtype && ?o != ?objtype ) .\n"
+ " ?s ?p ?o .\n"
+ "}";
ModelQueryAdapter mqa = new ModelQueryAdapter( query );
mqa.bind( "subtype", subtype );
mqa.bind( "objtype", objtype );
mqa.bind( "predtype", predtype );
mqa.useInferred( true );
Model model = engine.constructNoEx( mqa );
// we get inferred rel types as well as declared types, so if we have
// both, use the declared type
List<Statement> removers = new ArrayList<>();
for ( Statement s : model ) {
URI subj = URI.class.cast( s.getSubject() );
URI obj = URI.class.cast( s.getObject() );
Model filts = model.filter( subj, null, obj );
if ( filts.size() > 1 ) {
removers.add( new StatementImpl( subj, predtype, obj ) );
}
}
model.removeAll( removers );
// round two: get properties for the relationships if they exist
if ( !( null == propsToInclude || propsToInclude.isEmpty() ) ) {
String propq = "CONSTRUCT { ?p ?prop ?propval } WHERE {\n"
+ " ?p rdfs:subPropertyOf+ ?predtype ; ?prop ?propval .\n"
+ " VALUES ?prop {" + Utility.implode( propsToInclude ) + "}.\n"
+ "}";
ModelQueryAdapter propqa = new ModelQueryAdapter( propq );
propqa.bind( "predtype", predtype );
propqa.setModel( model );
propqa.useInferred( false );
engine.constructNoEx( propqa );
}
return model;
}
示例6: getOneRelationshipsData
import org.openrdf.model.Model; //导入方法依赖的package包/类
private Collection<NodeAndPropertyValues> getOneRelationshipsData( URI subjectType,
URI predicateType, URI objectType, final Collection<URI> properties,
Map<Resource, String> labels ) {
log.debug( "getOneRelData for " + subjectType.getLocalName() + "->"
+ predicateType.getLocalName() + "->" + objectType.getLocalName() );
Model model = NodeDerivationTools.getInstances( subjectType, predicateType,
objectType, properties, engine );
Set<Resource> needlabels = new HashSet<>( model.subjects() );
needlabels.addAll( model.predicates() );
Model rels = new TreeModel();
Model props = new TreeModel();
model.forEach( new Consumer<Statement>() {
@Override
public void accept( Statement t ) {
if ( t.getObject() instanceof URI ) {
rels.add( t );
needlabels.add( Resource.class.cast( t.getObject() ) );
}
else {
props.add( t );
}
}
} );
List<NodeAndPropertyValues> list = new ArrayList<>();
for ( Statement s : rels ) {
URI in = URI.class.cast( s.getSubject() );
URI out = URI.class.cast( s.getObject() );
NodeAndPropertyValues nap = new NodeAndPropertyValues( in, out );
list.add( nap );
for ( Statement p : props.filter( s.getPredicate(), null, null ) ) {
nap.put( p.getPredicate(), p.getObject() );
}
}
// don't refetch stuff already in the labels cache
needlabels.removeAll( labels.keySet() );
labels.putAll( Utility.getInstanceLabels( needlabels, engine ) );
return list;
}
示例7: testInsertDelete
import org.openrdf.model.Model; //导入方法依赖的package包/类
/**
* Insert a triple into the triplestore. Then run a SPARQL delete/insert/where update to replace the triple
* with a new triple and check if the update was successful.
*
* @throws IOException
* @throws RDFHandlerException
* @throws InterruptedException
*/
@Test
@Concurrent(count = 5)
@Repeating(repetition = 20)
public void testInsertDelete() throws IOException, RDFHandlerException, InterruptedException {
try {
// subject and predicate remain the same over updates
URI subject = randomURI();
URI predicate = randomURI();
// create a statement in the triple store
Model model = new TreeModel();
model.add(new StatementImpl(subject, predicate, randomObject()));
redlink.importDataset(model, TEST_DATASET);
log.debug("inserted random triple");
Model exported1 = redlink.exportDataset(TEST_DATASET);
Assert.assertFalse(exported1.isEmpty());
for(Statement stmt : model) {
Assert.assertTrue("triple " + stmt + " not contained in exported data", exported1.contains(stmt));
}
// run an DELETE/INSERT update query, replacing the old value with a new value
String updateTmpl = "DELETE { ?s <%s> ?o } INSERT { ?s <%s> \"Test\" } WHERE { ?s <%s> ?o . FILTER(?s = <%s>) }";
String update = String.format(updateTmpl, predicate.stringValue(), predicate.stringValue(), predicate.stringValue(), subject.stringValue());
redlink.sparqlUpdate(update, TEST_DATASET);
// check current state of dataset
Model exported2 = redlink.exportDataset(TEST_DATASET);
Assert.assertFalse(exported2.isEmpty());
Model filtered = exported2.filter(subject, predicate, null);
Assert.assertFalse(filtered.isEmpty());
Assert.assertEquals("Test", filtered.iterator().next().getObject().stringValue());
redlink.deleteResource(subject.stringValue(), TEST_DATASET);
} catch (RuntimeException ex) {
log.error("exception: ",ex);
Assert.fail(ex.getMessage());
}
}
示例8: getChangeSetUri
import org.openrdf.model.Model; //导入方法依赖的package包/类
private URI getChangeSetUri(Model changeSet) {
Model typeSubjects = changeSet.filter(null, RDF.TYPE, new URIImpl(Namespaces.CS_NAMESPACE.getName() + "ChangeSet"));
return (URI) typeSubjects.subjects().iterator().next();
}