本文整理汇总了Java中org.openrdf.model.Model类的典型用法代码示例。如果您正苦于以下问题:Java Model类的具体用法?Java Model怎么用?Java Model使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Model类属于org.openrdf.model包,在下文中一共展示了Model类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getUser
import org.openrdf.model.Model; //导入依赖的package包/类
private static User getUser( Resource id, RepositoryConnection rc )
throws RepositoryException {
LinkedHashModel model = new LinkedHashModel( Iterations.asList(
rc.getStatements( id, null, null, false ) ) );
org.openrdf.model.Model namer = model.filter( id, FOAF.ACCOUNT, null );
RemoteUserImpl user = new RemoteUserImpl( namer.objectString() );
model.removeAll( namer );
for ( Statement stmt : model ) {
URI pred = stmt.getPredicate();
String val = stmt.getObject().stringValue();
for ( Map.Entry<UserProperty, URI> en : PROPMAP.entrySet() ) {
if ( en.getValue().equals( pred ) ) {
user.setProperty( en.getKey(), val );
}
}
}
return user;
}
示例2: getLinksBetween
import org.openrdf.model.Model; //导入依赖的package包/类
@Override
public Model getLinksBetween( URI subtype, URI objtype ) {
String query = "CONSTRUCT{ ?s ?p ?o } WHERE { \n"
+ " ?mm a semtool:StructureData ;\n"
+ " rdf:predicate ?p ;\n"
+ " rdfs:domain ?s ;\n"
+ " rdfs:range ?o .\n";
// + "}"
Map<String, Value> bindings = new HashMap<>();
if ( !Constants.ANYNODE.equals( subtype ) ) {
query += " ?dom a|rdfs:subClassOf* ?s .\n";
bindings.put( "dom", subtype );
}
if ( !Constants.ANYNODE.equals( objtype ) ) {
query += " ?ran a|rdfs:subClassOf* ?o .\n";
bindings.put( "ran", objtype );
}
query += "}";
ModelQueryAdapter modelqa = new ModelQueryAdapter( query );
modelqa.setBindings( bindings );
return engine.constructNoEx( modelqa );
}
示例3: getConnectedConceptTypes
import org.openrdf.model.Model; //导入依赖的package包/类
@Override
public Model getConnectedConceptTypes( Collection<URI> instances ) {
final String query = "CONSTRUCT{ ?s ?p ?o } WHERE { \n"
+ " ?mm a semtool:StructureData ;\n"
+ " rdf:predicate ?p ;\n"
+ " rdfs:domain ?s ;\n"
+ " rdfs:range ?o .\n";
String implosion = Utility.implode( instances );
LinkedHashModel model = new LinkedHashModel();
ModelQueryAdapter subjects = new ModelQueryAdapter( query
+ " ?dom a|rdfs:subClassOf* ?s . VALUES ?dom {" + implosion + "} }", model );
ModelQueryAdapter objects = new ModelQueryAdapter( query
+ " ?ran a|rdfs:subClassOf* ?o . VALUES ?ran {" + implosion + "} }", model );
engine.constructNoEx( subjects );
engine.constructNoEx( objects );
return model;
}
示例4: rebuildConceptProps
import org.openrdf.model.Model; //导入依赖的package包/类
private Model rebuildConceptProps( List<URI> concepts ) {
String cimplosion = Utility.implode( concepts );
// now see what properties are on concepts and edges
String query = "SELECT DISTINCT ?type ?prop WHERE {\n"
+ " ?s ?prop ?propval . FILTER ( isLiteral( ?propval ) )\n"
+ " ?s a|rdfs:subClassOf+ ?type .\n"
+ " FILTER ( ?prop != rdfs:label ) .\n"
+ "} VALUES ?type { " + cimplosion + " }";
ModelQueryAdapter mqa = new ModelQueryAdapter( query ) {
@Override
public void handleTuple( BindingSet set, ValueFactory fac ) {
URI type = URI.class.cast( set.getValue( "type" ) );
URI prop = URI.class.cast( set.getValue( "prop" ) );
result.add( type, prop, Constants.ANYNODE );
}
};
return engine.queryNoEx( mqa );
}
示例5: rebuildEdges
import org.openrdf.model.Model; //导入依赖的package包/类
private Model rebuildEdges( List<URI> concepts, List<URI> edges ) {
String cimplosion = Utility.implode( concepts );
String eimplosion = Utility.implode( edges );
// now see what concepts connect to others via our edge types
String query = "CONSTRUCT { ?stype ?rtype ?otype } WHERE {\n"
+ " ?s a|rdfs:subClassOf+ ?stype .\n"
+ " ?o a|rdfs:subClassOf+ ?otype .\n"
+ " ?r a|rdfs:subPropertyOf+ ?rtype .\n"
+ " ?s ?r ?o .\n"
+ " VALUES ?stype {" + cimplosion + "} .\n"
+ " VALUES ?otype {" + cimplosion + "} .\n"
+ " VALUES ?rtype {" + eimplosion + "} .\n"
+ "}";
final Model model = engine.constructNoEx( new ModelQueryAdapter( query ) );
return model;
}
示例6: save
import org.openrdf.model.Model; //导入依赖的package包/类
private void save( Model model ) {
// get old model, which we'll remove
Model olds = getModel();
ModificationExecutor eme = new ModificationExecutorAdapter( true ) {
@Override
public void exec( RepositoryConnection conn ) throws RepositoryException {
conn.remove( olds );
conn.add( model );
}
};
try {
engine.execute( eme );
}
catch ( Exception e ) {
log.error( e, e );
}
}
示例7: getConstruct
import org.openrdf.model.Model; //导入依赖的package包/类
public static Model getConstruct( QueryExecutor<Model> query,
RepositoryConnection rc, boolean dobindings )
throws RepositoryException, MalformedQueryException, QueryEvaluationException {
String sparql = processNamespaces( dobindings ? query.getSparql()
: query.bindAndGetSparql(), query.getNamespaces() );
GraphQuery tq = rc.prepareGraphQuery( QueryLanguage.SPARQL, sparql );
tq.setIncludeInferred( query.usesInferred() );
if ( dobindings ) {
query.setBindings( tq, rc.getValueFactory() );
}
GraphQueryResult gqr = tq.evaluate();
while ( gqr.hasNext() ) {
query.getResults().add( gqr.next() );
}
gqr.close();
return query.getResults();
}
示例8: 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;
}
示例9: 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;
}
示例10: 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;
}
示例11: ttlToStdout
import org.openrdf.model.Model; //导入依赖的package包/类
public static void ttlToStdout( Model model ) {
TurtleWriter tw = new TurtleWriter( System.out );
try {
tw.startRDF();
for ( Map.Entry<String, String> en : DEFAULTNAMESPACES.entrySet() ) {
tw.handleNamespace( en.getKey(), en.getValue() );
}
for ( Statement s : model ) {
tw.handleStatement( s );
}
tw.endRDF();
}
catch ( Exception e ) {
log.error( e, e );
}
}
示例12: testExec3
import org.openrdf.model.Model; //导入依赖的package包/类
@Test
public void testExec3() throws Exception {
InMemorySesameEngine eng = InMemorySesameEngine.open();
StatementAddingExecutor sae = new StatementAddingExecutor(
Arrays.asList( new StatementImpl( RDFS.DOMAIN, RDFS.LABEL,
new LiteralImpl( "label" ) ) ), true );
sae.resetStatements( new StatementImpl( RDFS.DOMAIN, RDFS.LABEL,
new LiteralImpl( "tester" ) ) );
Model before = eng.toModel();
eng.execute( sae );
Model after = eng.toModel();
eng.closeDB();
assertTrue( ( before.size() + 1 ) == after.size() );
assertTrue( after.contains( RDFS.DOMAIN, RDFS.LABEL, new LiteralImpl( "tester" ) ) );
assertFalse( after.contains( RDFS.DOMAIN, RDFS.LABEL, new LiteralImpl( "label" ) ) );
}
示例13: 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 );
}
示例14: testImportXlsModern
import org.openrdf.model.Model; //导入依赖的package包/类
@Test
public void testImportXlsModern() throws Exception {
engine.setBuilders( UriBuilder.getBuilder( DATAURI ),
UriBuilder.getBuilder( SCHEMAURI ) );
EngineLoader el = new EngineLoader();
el.setDefaultBaseUri( BASEURI, false );
ImportData errors = new ImportData();
el.loadToEngine( Arrays.asList( CUSTOM ), engine, true, errors );
Model owls = el.getMetamodel();
el.release();
if ( log.isTraceEnabled() ) {
File tmpdir = FileUtils.getTempDirectory();
try ( Writer w = new BufferedWriter( new FileWriter( new File( tmpdir,
"custom-mm.nt" ) ) ) ) {
engine.getRawConnection().export( new NTriplesWriter( w ) );
}
}
compareOwls( owls, CUSTOM_EXP, engine.getSchemaBuilder() );
compareData( engine.getRawConnection(), getExpectedGraph( CUSTOM_EXP ),
engine.getSchemaBuilder(), engine.getDataBuilder() );
}
示例15: testImportXlsSpecial
import org.openrdf.model.Model; //导入依赖的package包/类
@Test
public void testImportXlsSpecial() throws Exception {
engine.setBuilders( UriBuilder.getBuilder( DATAURI ),
UriBuilder.getBuilder( SCHEMAURI ) );
EngineLoader el = new EngineLoader();
el.setDefaultBaseUri( BASEURI, false );
ImportData errors = new ImportData();
el.loadToEngine( Arrays.asList( TESTSPECIAL ), engine, true, errors );
Model owls = el.getMetamodel();
el.release();
if ( log.isTraceEnabled() ) {
File tmpdir = FileUtils.getTempDirectory();
try ( Writer w = new BufferedWriter( new FileWriter( new File( tmpdir,
"test-special.nt" ) ) ) ) {
engine.getRawConnection().export( new NTriplesWriter( w ) );
}
}
compareOwls( owls, TESTSPECIAL_EXP, engine.getSchemaBuilder() );
compareData( engine.getRawConnection(), getExpectedGraph( TESTSPECIAL_EXP ),
engine.getSchemaBuilder(), engine.getDataBuilder() );
}