本文整理了Java中com.hp.hpl.jena.rdf.model.Model
类的一些代码示例,展示了Model
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Model
类的具体详情如下:
包路径:com.hp.hpl.jena.rdf.model.Model
类名称:Model
[英]An RDF Model.
An RDF model is a set of Statements. Methods are provided for creating resources, properties and literals and the Statements which link them, for adding statements to and removing them from a model, for querying a model and set operations for combining models.
Models may create Resources [URI nodes and bnodes]. Creating a Resource does not make the Resource visible to the model; Resources are only "in" Models if Statements about them are added to the Model. Similarly the only way to "remove" a Resource from a Model is to remove all the Statements that mention it.
When a Resource or Literal is created by a Model, the Model is free to re-use an existing Resource or Literal object with the correct values, or it may create a fresh one. [All Jena RDFNodes and Statements are immutable, so this is generally safe.]
This interface defines a set of primitive methods. A set of convenience methods which extends this interface, e.g. performing automatic type conversions and support for enhanced resources, is defined in ModelCon.
System Properties
Some of the methods, e.g. the read methods, may have to traverse a firewall. This can be accomplished using the standard java method of setting system properties. To use a socks proxy, include on the java command line:
-DsocksProxyHost=[your-proxy-domain-name-or-ip-address]
To use an http proxy, include on the command line:
-DproxySet=true -DproxyHost=[your-proxy] -DproxyPort=[your-proxy-port-number]
Alternatively, these properties can be set programatically, e.g.
<<$0$>>
[中]
代码示例来源:origin: org.appdapter/org.appdapter.lib.remote
/**
* Returns a pair of models. The first contains any statement containing at
* least one blank node. The second contains all remaining statements.
* @param g
* @return
*/
private Model[] separateStatementsWithBlankNodes(Graph g) {
Model gm = ModelFactory.createModelForGraph(g);
Model blankNodeModel = ModelFactory.createDefaultModel();
Model nonBlankNodeModel = ModelFactory.createDefaultModel();
StmtIterator sit = gm.listStatements();
while (sit.hasNext()) {
Statement stmt = sit.nextStatement();
if (!stmt.getSubject().isAnon() && !stmt.getObject().isAnon()) {
nonBlankNodeModel.add(stmt);
} else {
blankNodeModel.add(stmt);
}
}
Model[] result = new Model[2];
result[0] = blankNodeModel;
result[1] = nonBlankNodeModel;
return result;
}
代码示例来源:origin: org.w3/ldp-testsuite
protected Model getDefaultModel() {
Model model = ModelFactory.createDefaultModel();
Resource resource = model.createResource("",
model.createResource("http://example.com/ns#Bug"));
resource.addProperty(RDF.type, model.createResource(LDP.RDFSource.stringValue()));
resource.addProperty(
model.createProperty("http://example.com/ns#severity"), "High");
resource.addProperty(DCTerms.title, "Another bug to test.");
resource.addProperty(DCTerms.description, "Issues that need to be fixed.");
return model;
}
代码示例来源:origin: openimaj/openimaj
private synchronized void prepareModel() {
m = ModelFactory.createDefaultModel();
m.read(new StringReader(baseModelString), "");
// m.read(GeneralJSONRDF.class.getResourceAsStream("rdf/base_usmf.rdf"),
// "");
}
代码示例来源:origin: net.sf.taverna.t2/provenance-client
void init() {
m = ModelFactory.createDefaultModel();
m.setNsPrefix("janus",JanusOntology.getURI());
m.setNsPrefix(PROVENIR_PREFIX, PROVENIR_NS);
m.setNsPrefix(OBO_PREFIX, OBO_NS);
m.setNsPrefix(RDFS_PREFIX, RDFS_NS);
m.setNsPrefix(JANUS_PREFIX, JANUS_NS);
m.setNsPrefix(MYGRID_PREFIX, MYGRID_NS);
m.setNsPrefix(RDF_PREFIX, RDF_NS);
RDFS_COMMENT = m.createProperty(RDFS_NS, "comment");
}
代码示例来源:origin: stackoverflow.com
public static void main(String[] args) {
String fileNameOrUri = "src/a/rdfexample.ntriple";
Model model = ModelFactory.createDefaultModel();
InputStream is = FileManager.get().open(fileNameOrUri);
if (is != null) {
model.read(is, null, "N-TRIPLE");
model.write(System.out, "TURTLE");
} else {
System.err.println("cannot read " + fileNameOrUri);;
}
}
代码示例来源:origin: com.hp.hpl.jena/arq
public Resource asRDF(Model model, boolean result)
{
Resource results = model.createResource() ;
results.addProperty(RDF.type, ResultSetGraphVocab.ResultSet) ;
Literal lit = model.createTypedLiteral(result) ;
results.addProperty(ResultSetGraphVocab.p_boolean, lit) ;
return results ;
}
代码示例来源:origin: net.sf.taverna.t2.activities/sadi-activity
public void setContents(String contentsAsString) {
if (contentsAsString.startsWith("<rdf:RDF")) {
Model model = ModelFactory.createDefaultModel();
model.read(new StringReader(contentsAsString), null);
Set<Resource> subjects = model.listSubjects().toSet();
Set<RDFNode> objects = model.listObjects().toSet();
subjects.removeAll(objects);
node = subjects.iterator().next();
} else {
node = RdfUtils.createTypedLiteral(contentsAsString);
}
}
代码示例来源:origin: net.sf.taverna.t2.activities/sadi-activity
/**
* Test method for
* {@link net.sf.taverna.t2.reference.sadi.RDFReference#setContents(java.lang.String)}
* .
*/
@Test
public void testSetContents() {
rdfReference.setContents("5");
assertEquals("5", rdfReference.getContents());
rdfReference.setContents(rdfURIResourceString);
assertTrue(rdfReference.getContents().contains(
"UniProt_Record rdf:about=\"http://purl.uniprot.org/uniprot/P12345\""));
rdfReference.setContents(rdfResourceString);
Model model1 = ModelFactory.createDefaultModel().read(new StringReader(rdfResourceString),
null);
Model model2 = ModelFactory.createDefaultModel().read(
new StringReader(rdfReference.getContents()), null);
assertTrue(model1.isIsomorphicWith(model2));
}
代码示例来源:origin: org.dataconservancy.packaging/dcs-package-shared
new SimpleSelector(null, ResourceMapConstants.IS_DESCRIBED_BY_PROPERTY, (Object) null);
StmtIterator sItr = m.listStatements(isDescribedBySelector);
while (sItr.hasNext()) {
final Statement stmt = sItr.next();
final String rdfUri = stmt.getObject().toString();
if (loadedRems.contains(rdfUri)) {
LOG.trace("Already loaded ReM from {}", rdfUri);
Model loaded = ModelFactory.createDefaultModel();
RDFReader reader = loaded.getReader();
reader.setProperty(ResourceMapConstants.JENA_ERROR_MODE_URI, ResourceMapConstants.JENA_ERROR_MODE_STRICT);
ResourceMapUtil.loadRDF(reader, loaded, baseDir, rdfUri);
loadedRems.add(rdfUri);
m = load(m.union(loaded), baseDir, loadedRems);
代码示例来源:origin: org.apache.clerezza.ext/org.apache.jena.jena-core
protected static void addRangeTypes( Model result, Model schema )
{
Model toAdd = ModelFactory.createDefaultModel();
for (StmtIterator it = schema.listStatements( ANY, RDFS.range, ANY ); it.hasNext();)
{
Statement s = it.nextStatement();
RDFNode type = s.getObject();
Property property = s.getSubject().as( Property.class );
for (StmtIterator x = result.listStatements( ANY, property, ANY ); x.hasNext();)
{
RDFNode ob = x.nextStatement().getObject();
if (ob.isResource()) toAdd.add( (Resource) ob, RDF.type, type );
}
}
result.add( toAdd );
}
代码示例来源:origin: epimorphics/elda
private Model normaliseLiterals(Model m) {
Model result = ModelFactory.createDefaultModel();
for (StmtIterator it = m.listStatements(); it.hasNext();) {
result.add(normaliseLiterals(it.next()));
}
return result;
}
代码示例来源:origin: org.apache.clerezza.ext/org.apache.jena.jena-core
private static List<Resource> equivalentTypes( Resource type )
{
List<Resource> types = new ArrayList<Resource>();
types.add( type );
for (StmtIterator it = type.getModel().listStatements( ANY, OWL.equivalentClass, type ); it.hasNext();)
types.add( it.nextStatement().getSubject() );
return types;
}
代码示例来源:origin: org.apache.clerezza.ext/org.apache.jena.jena-core
protected static void addSupertypes( Model result )
{
Model temp = ModelFactory.createDefaultModel();
for (StmtIterator it = result.listStatements( ANY, RDF.type, ANY ); it.hasNext();)
{
Statement s = it.nextStatement();
Resource c = AssemblerHelp.getResource( s );
for (StmtIterator subclasses = result.listStatements( c, RDFS.subClassOf, ANY ); subclasses.hasNext();)
{
RDFNode type = subclasses.nextStatement().getObject();
// System.err.println( ">> adding super type: subject " + s.getSubject() + ", type " + type );
temp.add( s.getSubject(), RDF.type, type );
}
}
result.add( temp );
}
代码示例来源:origin: org.appdapter/org.appdapter.lib.remote
private void verbModel(Model model, String verb) {
Model m = ModelFactory.createDefaultModel();
int testLimit = 1000;
StmtIterator stmtIt = model.listStatements();
int count = 0;
try {
while (stmtIt.hasNext()) {
count++;
m.add(stmtIt.nextStatement());
if (count % testLimit == 0 || !stmtIt.hasNext()) {
StringWriter sw = new StringWriter();
m.write(sw, "N-TRIPLE");
StringBuffer updateStringBuff = new StringBuffer();
String graphURI = graph.getGraphURI();
updateStringBuff.append(verb + " DATA { " + ((graphURI != null) ? "GRAPH <" + graphURI + "> { " : ""));
updateStringBuff.append(sw);
updateStringBuff.append(((graphURI != null) ? " } " : "") + " }");
String updateString = updateStringBuff.toString();
//log.info(updateString);
graph.executeUpdate(updateString);
m.removeAll();
}
}
} finally {
stmtIt.close();
}
}
代码示例来源:origin: net.sourceforge.ondex.modules/rdf
Resource cC = model.createResource(ONDEXRdf.ccToUri(graphURI, cc));
rdfMetadata(cC, cc);
if (cc.getSpecialisationOf() != null) cC.addProperty(RDFS.subClassOf, model.createResource(ONDEXRdf.ccToUri(graphURI, cc.getSpecialisationOf())));
Resource rT = model.createResource(ONDEXRdf.rtToUri(graphURI, rt));
rdfMetadata(rT, rt);
if (rt.getSpecialisationOf() != null) rT.addProperty(RDFS.subPropertyOf, model.createResource(ONDEXRdf.rtToUri(graphURI, rt.getSpecialisationOf())));
Property aN = model.createProperty(ONDEXRdf.attributeNameToUri(graphURI, an));
rdfMetadata(aN, an);
if (an.getSpecialisationOf() != null) aN.addProperty(RDFS.subPropertyOf, model.createProperty(ONDEXRdf.attributeNameToUri(graphURI, an.getSpecialisationOf())));
for(DataSource dataSource : md.getDataSources()) rdfMetadata(model.createResource(ONDEXRdf.dataSourceToUri(graphURI, dataSource)), dataSource);
for(EvidenceType et : md.getEvidenceTypes()) rdfMetadata(model.createResource(ONDEXRdf.etToUri(graphURI, et)), et);
Resource cR = model.createResource(ONDEXRdf.conceptToUri(graphURI, c));
cRap(cR, model.createProperty(ONDEXRdf.annotationUri), c.getAnnotation());
for(ConceptAccession ca : c.getConceptAccessions()) {
cR.addProperty(model.createProperty(ONDEXRdf.conceptAccessionUri), ca.getAccession());
cR.addProperty(model.createProperty(ONDEXRdf.conceptNameUri), cn.getName());
cRap(cR, model.createProperty(ONDEXRdf.descriptionUri), c.getDescription());
cR.addProperty(model.createProperty(ONDEXRdf.elementOfUri), model.createResource(ONDEXRdf.dataSourceToUri(graphURI, c.getElementOf())));
cR.addProperty(RDF.type, model.createResource(ONDEXRdf.ccToUri(graphURI, c.getOfType())));
cRap(cR, model.createProperty(ONDEXRdf.pidUri), c.getPID());
代码示例来源:origin: org.apache.clerezza.ext/org.apache.jena.jena-core
protected static void addSubclassesFrom( Model result, Model schema )
{
for (StmtIterator it = schema.listStatements( ANY, RDFS.subClassOf, ANY ); it.hasNext();)
{
Statement s = it.nextStatement();
if (s.getSubject().isURIResource() && s.getObject().isURIResource()) result.add( s );
}
}
代码示例来源:origin: epimorphics/elda
toScan.setNsPrefixes( pm );
Resource predicate = toScan.createProperty( "http://example.com/root#predicate" );
Model meta = ModelFactory.createDefaultModel();
Resource exec = meta.createResource( "fake:exec" );
ShortnameService sns = new StandardShortnameService();
Resource tb = meta.listStatements( null, API.termBinding, Any ).nextStatement().getResource();
assertTrue( meta.contains( tb, API.label, "this_predicate" ) );
assertTrue( meta.contains( tb, API.property, predicate ) );
代码示例来源:origin: org.apache.clerezza.ext/org.apache.jena.jena-core
Model m = ModelFactory.createDefaultModel();
for (StmtIterator i = r.listProperties(); i.hasNext(); ) {
Statement s = i.nextStatement();
m.add( s );
if (s.getObject() instanceof Resource) {
queue.add( s.getObject() );
代码示例来源:origin: org.apache.clerezza.ext/org.apache.jena.jena-core
protected static void addDomainTypes( Model result, Model schema )
{
for (StmtIterator it = schema.listStatements( ANY, RDFS.domain, ANY ); it.hasNext();)
{
Statement s = it.nextStatement();
Property property = s.getSubject().as( Property.class );
RDFNode type = s.getObject();
for (StmtIterator x = result.listStatements( ANY, property, ANY ); x.hasNext();)
{
Statement t = x.nextStatement();
result.add( t.getSubject(), RDF.type, type );
}
}
}
代码示例来源:origin: org.apache.stanbol/org.apache.stanbol.rules.manager
private static URI getSWRLVariable(String argument){
Resource variableResource = null;
String variableString = argument.substring(1);
variableResource = ModelFactory.createDefaultModel().createResource(kb.getPrefixURI("var")+variableString);
try {
return new URI(variableResource.getURI());
} catch (URISyntaxException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
}
}
内容来源于网络,如有侵权,请联系作者删除!