当前位置: 首页>>代码示例>>Java>>正文


Java Model.filter方法代码示例

本文整理汇总了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() );
}
 
开发者ID:Ostrich-Emulators,项目名称:semtool,代码行数:10,代码来源:EngineLoaderTest.java

示例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 );
		}
	}
}
 
开发者ID:Ostrich-Emulators,项目名称:semtool,代码行数:12,代码来源:DBToLoadingSheetExporter.java

示例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;
}
 
开发者ID:dkmfbk,项目名称:pikes,代码行数:36,代码来源:Renderer.java

示例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);
}
 
开发者ID:podd,项目名称:podd-examples,代码行数:8,代码来源:ExamplePoddClient.java

示例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;
}
 
开发者ID:Ostrich-Emulators,项目名称:semtool,代码行数:53,代码来源:NodeDerivationTools.java

示例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;
}
 
开发者ID:Ostrich-Emulators,项目名称:semtool,代码行数:46,代码来源:DBToLoadingSheetExporter.java

示例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());
    }
}
 
开发者ID:redlink-gmbh,项目名称:redlink-java-sdk,代码行数:57,代码来源:RepeatedUpdateTest.java

示例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();
}
 
开发者ID:rsine,项目名称:rsine,代码行数:5,代码来源:PersistAndNotifyProvider.java


注:本文中的org.openrdf.model.Model.filter方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。