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


Java Model.add方法代码示例

本文整理汇总了Java中org.openrdf.model.Model.add方法的典型用法代码示例。如果您正苦于以下问题:Java Model.add方法的具体用法?Java Model.add怎么用?Java Model.add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.openrdf.model.Model的用法示例。


在下文中一共展示了Model.add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getModel

import org.openrdf.model.Model; //导入方法依赖的package包/类
public static Model getModel( InsightManager im, User user ) {
	Model statements = new LinkedHashModel();
	int idx = 0;

	RDFParser parser = new TurtleParser();
	StatementCollector coll = new StatementCollector();
	parser.setRDFHandler( coll );
	try ( InputStream is = IEngine.class.getResourceAsStream( "/models/sempers.ttl" ) ) {
		parser.parse( is, SEMPERS.BASE_URI );
	}
	catch ( Exception e ) {
		log.warn( "could not include sempers.ttl ontology in statements", e );
	}

	statements.addAll( coll.getStatements() );

	ValueFactory vf = new ValueFactoryImpl();
	for ( Perspective p : im.getPerspectives() ) {
		statements.addAll( getStatements( p, user ) );
		statements.add( new StatementImpl( p.getId(), OLO.index,
				vf.createLiteral( idx++ ) ) );
	}

	return statements;
}
 
开发者ID:Ostrich-Emulators,项目名称:semtool,代码行数:26,代码来源:InsightManagerImpl.java

示例2: getPerspectiveStatements

import org.openrdf.model.Model; //导入方法依赖的package包/类
protected static Model getPerspectiveStatements( Perspective p,
		ValueFactory vf, UriBuilder urib, User user ) {

	Model statements = new LinkedHashModel();
	URI pid = p.getId();
	Date now = new Date();

	statements.add( new StatementImpl( pid, RDF.TYPE, SEMPERS.Perspective ) );
	statements.add( new StatementImpl( pid, RDFS.LABEL,
			vf.createLiteral( p.getLabel() ) ) );
	if ( null != p.getDescription() ) {
		statements.add( new StatementImpl( pid, DCTERMS.DESCRIPTION,
				vf.createLiteral( p.getDescription() ) ) );
	}

	statements.add( new StatementImpl( pid, DCTERMS.CREATED,
			vf.createLiteral( now ) ) );
	statements.add( new StatementImpl( pid, DCTERMS.MODIFIED,
			vf.createLiteral( now ) ) );
	statements.add( new StatementImpl( pid, DCTERMS.CREATOR,
			vf.createLiteral( getAuthorInfo( user ) ) ) );

	return statements;
}
 
开发者ID:Ostrich-Emulators,项目名称:semtool,代码行数:25,代码来源:InsightManagerImpl.java

示例3: getParameterStatements

import org.openrdf.model.Model; //导入方法依赖的package包/类
protected static Model getParameterStatements( Parameter parameter,
		URI predicateUri, URI queryUri, ValueFactory vf, UriBuilder urib,
		User user ) {

	Model statements = new LinkedHashModel();

	URI pid = parameter.getId();

	statements.add( new StatementImpl( pid, RDFS.LABEL,
			vf.createLiteral( parameter.getLabel() ) ) );

	statements.add( new StatementImpl( pid, SPL.predicate, predicateUri ) );
	statements.add( new StatementImpl( pid, SP.query, queryUri ) );

	statements.add( new StatementImpl( predicateUri, RDFS.LABEL,
			vf.createLiteral( parameter.getLabel() ) ) );
	statements.add( new StatementImpl( queryUri, SP.text,
			vf.createLiteral( parameter.getDefaultQuery() ) ) );

	return statements;
}
 
开发者ID:Ostrich-Emulators,项目名称:semtool,代码行数:22,代码来源:InsightManagerImpl.java

示例4: testGetInstancesNoPropsAvailable

import org.openrdf.model.Model; //导入方法依赖的package包/类
@Test
public void testGetInstancesNoPropsAvailable() throws Exception {
	// this is just extra stuff that shouldn't be returned in the tests
	final URI REL = OWLB.getRelationUri().build();
	final URI EXTRA = OWLB.build( "AnotherRelType" );
	final URI EXTRAIMPL = DATAB.build( "AnotherRel" );

	final URI ALAN = DATAB.build( "Alan" );
	final URI CADILLAC = DATAB.build( "Cadillac" );

	engine.getRawConnection().add( EXTRA, RDFS.SUBPROPERTYOF, REL );
	engine.getRawConnection().add( EXTRAIMPL, RDF.TYPE, REL );


	Model expected = new LinkedHashModel();
	expected.add( YURI, YPY, YUGO );
	expected.add( ALAN, PURCHASE, CADILLAC );

	Model model = NodeDerivationTools.getInstances( HUMAN, PURCHASE, CAR,
			null, engine );
	assertEquals( expected, model );
}
 
开发者ID:Ostrich-Emulators,项目名称:semtool,代码行数:23,代码来源:NodeDerivationToolsTest.java

示例5: create

import org.openrdf.model.Model; //导入方法依赖的package包/类
/**
 * Creates graph nodes from the given data. If the {@code Value[]}s have
 * length 1, the values are expected to be nodes ({@link Resource}s. If they
 * have length 3, then they are repackaged as Statements, and forwarded on to
 * {@link #create(org.openrdf.model.Model, com.ostrichemulators.semtool.rdf.engine.api.IEngine) }.
 * Anything else will throw an exception
 *
 * @param data the data to add are expected to be
 * @param headers ignored
 * @param engine
 * @throws IllegalArgumentException
 *
 */
@Override
public void create( List<Value[]> data, List<String> headers, IEngine engine ) {
	List<URI> nodes = new ArrayList<>();
	Model model = new LinkedHashModel();
	for ( Value[] row : data ) {
		URI s = URI.class.cast( row[0] );
		if ( 1 == row.length ) {
			nodes.add( s );
		}
		else if ( 3 == row.length ) {
			URI p = URI.class.cast( row[1] );
			Value o = row[2];

			model.add( s, p, o );
		}
		else {
			throw new IllegalArgumentException( "Values cannot be converted for graph usage" );
		}
	}

	add( model, nodes, engine );
}
 
开发者ID:Ostrich-Emulators,项目名称:semtool,代码行数:36,代码来源:GraphPlaySheet.java

示例6: testRemoveElementsSinceLevel

import org.openrdf.model.Model; //导入方法依赖的package包/类
@Test
public void testRemoveElementsSinceLevel() {
	GraphDataModel gdm = new GraphDataModel();
	gdm.addGraphLevel( Arrays.asList( YURI ), eng, 1 );
	Model m = new LinkedHashModel();
	m.add( new StatementImpl( YURI, YPY, YUGO ) );
	gdm.addGraphLevel( m, eng, 2 );

	List<SEMOSSVertex> list = new ArrayList<>( gdm.getGraph().getVertices() );
	Collections.sort( list, VERTCOMP );

	SEMOSSVertex yuri = list.get( 1 );
	SEMOSSVertex yugo = list.get( 0 );

	assertTrue( gdm.presentAtLevel( yuri, 2 ) );
	assertTrue( gdm.presentAtLevel( yugo, 2 ) );
	assertEquals( 1, gdm.getGraph().getEdgeCount() );

	gdm.removeElementsSinceLevel( 1 );

	assertTrue( gdm.getGraph().getEdges().isEmpty() );
	assertEquals( yuri, gdm.getGraph().getVertices().iterator().next() );
}
 
开发者ID:Ostrich-Emulators,项目名称:semtool,代码行数:24,代码来源:GraphDataModelTest.java

示例7: testResourceReImported

import org.openrdf.model.Model; //导入方法依赖的package包/类
@Test
@Ignore
public void testResourceReImported() throws IOException, RDFParseException, RDFHandlerException, URISyntaxException {
    //first import data
    InputStream in = this.getClass().getResourceAsStream(TEST_FILE);
    Assume.assumeNotNull(in);
    final Model model = Rio.parse(in, buildDatasetBaseUri(credentials, status.getOwner(), TEST_DATASET), TEST_FILE_FORMAT);
    Assert.assertTrue(redlink.importDataset(model, TEST_DATASET, true));
    final SPARQLResult triples = redlink.sparqlTupleQuery(QUERY_SELECT, TEST_DATASET);
    Assert.assertNotNull(triples);
    Assert.assertEquals(TEST_FILE_TRIPLES, triples.size());

    //and then the actual test
    final String resource = buildDatasetBaseUri(credentials, status.getOwner(), TEST_DATASET) + TEST_RESOURCE;
    final ValueFactoryImpl vf = new ValueFactoryImpl();
    final Resource sesameResource = vf.createURI(resource);
    final Model resourceModel = new LinkedHashModel();
    resourceModel.add(sesameResource, vf.createURI("http://example.org/foo"), vf.createLiteral("foo"));
    Assert.assertTrue(redlink.importResource(resource, model, TEST_DATASET, true));
    final Model resourceModelFromApi = redlink.getResource(resource, TEST_DATASET);
    Assert.assertNotNull(resourceModelFromApi);
    Assert.assertEquals(resourceModel.size(), resourceModelFromApi.size());
}
 
开发者ID:redlink-gmbh,项目名称:redlink-java-sdk,代码行数:24,代码来源:DataTest.java

示例8: add

import org.openrdf.model.Model; //导入方法依赖的package包/类
/**
 * Add statements from the given statement iteration to the given model.
 *
 * @param model   the model to add the statements to
 * @param triples a closeable iteration of triples to add (e.g. a RepositoryResult<Statement>)
 * @param filters an optional list of filters; if any of the filters rejects the statement it is not added
 * @throws IOException
 * @throws RDFParseException
 */
public static <X extends Exception> void add(Model model, CloseableIteration<? extends Statement,X> triples, Predicate<Statement>... filters) throws X {
    try {
        rloop: while(triples.hasNext()) {
            Statement st = triples.next();

            for(Predicate<Statement> f : filters) {
                if(!f.test(st)) {
                    continue rloop;
                }
            }

            model.add(st);
        }
    } finally {
        triples.close();
    }
}
 
开发者ID:apache,项目名称:marmotta,代码行数:27,代码来源:ModelCommons.java

示例9: loadMetadataInternal

import org.openrdf.model.Model; //导入方法依赖的package包/类
private void loadMetadataInternal(Model metadata, String query) throws OpenRDFException {
    long startTime = System.currentTimeMillis();
    RepositoryConnection connection = constructSource.getRepository().getConnection();
    GraphQueryResult resultSet = null;
    try {
        resultSet = connection.prepareGraphQuery(QueryLanguage.SPARQL, query).evaluate();
        LOG.debug("ODCS-FusionTool: Metadata query took {} ms", System.currentTimeMillis() - startTime);
        while (resultSet.hasNext()) {
            Statement statement = resultSet.next();
            metadata.add(statement);
        }
    } finally {
        if (resultSet != null) {
            resultSet.close();
        }
        connection.close();
    }
}
 
开发者ID:mifeet,项目名称:LD-FusionTool,代码行数:19,代码来源:MetadataLoader.java

示例10: getStatementsToTranslate

import org.openrdf.model.Model; //导入方法依赖的package包/类
private Collection<Statement> getStatementsToTranslate(Repository repository, URI graph) throws RepositoryException, MalformedQueryException, QueryEvaluationException {
  String queryString = "SELECT ?s ?p ?o " +
          "FROM <" + graph + "> " +
          "WHERE {" +
          queryForPredicates(config.getPredicates())
          +
          "}";
  RepositoryConnection con = repository.getConnection();
  Model statements = new LinkedHashModel();
  try {
    TupleQuery tupleQuery = con.prepareTupleQuery(QueryLanguage.SPARQL, queryString);
    TupleQueryResult results = tupleQuery.evaluate();

    while (results.hasNext()) {
      BindingSet row = results.next();
      statements.add((URI) row.getValue("s"), (URI) row.getValue("p"), row.getValue("o"));
    }
  } finally {
    con.close();
  }

  return statements;
}
 
开发者ID:nvdk,项目名称:ods-lodms-plugins,代码行数:24,代码来源:WebTranslator.java

示例11: getMetadata

import org.openrdf.model.Model; //导入方法依赖的package包/类
@Override
public Model getMetadata() throws LDFusionToolException {
    if (metadataInput == null) {
        return new EmptyMetadataModel();
    }
    Model metadata = new TreeModel();
    RepositoryResult<Statement> metadataResult;
    try (CloseableRepositoryConnection connection = new CloseableRepositoryConnection(metadataInput.getConnection())) {
        metadataResult = connection.get().getStatements(null, null, null, false);
        while (metadataResult.hasNext()) {
            metadata.add(metadataResult.next());
        }
        return metadata;
    } catch (RepositoryException | DataUnitException e) {
        throw new LDFusionToolException("Error when loading metadata from input", e);
    }
}
 
开发者ID:mifeet,项目名称:FusionTool-DPU,代码行数:18,代码来源:FusionToolDpuComponentFactory.java

示例12: getOrderingStatements

import org.openrdf.model.Model; //导入方法依赖的package包/类
protected static Model getOrderingStatements( Perspective p,
		List<Insight> insights, ValueFactory vf, UriBuilder urib ) {
	Model statements = new LinkedHashModel();
	int idx = 0;
	for ( Insight i : insights ) {
		URI slot = urib.build( p.getLabel() + "-slot-" + Integer.toString( ++idx ) );
		statements.add( new StatementImpl( p.getId(), OLO.slot, slot ) );
		statements.add( new StatementImpl( slot, OLO.index, vf.createLiteral( idx ) ) );
		statements.add( new StatementImpl( slot, OLO.item, i.getId() ) );
	}

	return statements;
}
 
开发者ID:Ostrich-Emulators,项目名称:semtool,代码行数:14,代码来源:InsightManagerImpl.java

示例13: getConstraintStatements

import org.openrdf.model.Model; //导入方法依赖的package包/类
protected static Collection<Statement> getConstraintStatements( Insight ins,
		Collection<Parameter> params ) {
	Model statements = new LinkedHashModel();
	for ( Parameter p : params ) {
		statements.add( new StatementImpl( ins.getId(), SPIN.constraint, p.getId() ) );
	}
	return statements;
}
 
开发者ID:Ostrich-Emulators,项目名称:semtool,代码行数:9,代码来源:InsightManagerImpl.java

示例14: testAddGraphLevel_model_generic

import org.openrdf.model.Model; //导入方法依赖的package包/类
@Test
public void testAddGraphLevel_model_generic() throws RepositoryException {
	Model m = new LinkedHashModel();
	m.add( new StatementImpl( YURI, PURCHASE, YUGO ) );

	GraphDataModel gdm = new GraphDataModel();
	gdm.addGraphLevel( m, eng, 1 );

	DirectedGraph<SEMOSSVertex, SEMOSSEdge> graph = gdm.getGraph();
	assertEquals( 2, graph.getVertexCount() );
	assertEquals( 1, graph.getEdgeCount() );

	SEMOSSEdge edge = graph.getEdges().iterator().next();
	assertEquals( "3000 USD", edge.getValue( PRICE ).stringValue() );
}
 
开发者ID:Ostrich-Emulators,项目名称:semtool,代码行数:16,代码来源:GraphDataModelTest.java

示例15: testAddGraphLevel_model_specific

import org.openrdf.model.Model; //导入方法依赖的package包/类
@Test
public void testAddGraphLevel_model_specific() throws RepositoryException {
	Model m = new LinkedHashModel();
	m.add( new StatementImpl( YURI, YPY, YUGO ) );

	GraphDataModel gdm = new GraphDataModel();
	gdm.addGraphLevel( m, eng, 1 );

	DirectedGraph<SEMOSSVertex, SEMOSSEdge> graph = gdm.getGraph();
	assertEquals( 2, graph.getVertexCount() );
	assertEquals( 1, graph.getEdgeCount() );

	SEMOSSEdge edge = graph.getEdges().iterator().next();
	assertEquals( "3000 USD", edge.getValue( PRICE ).stringValue() );
}
 
开发者ID:Ostrich-Emulators,项目名称:semtool,代码行数:16,代码来源:GraphDataModelTest.java


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