本文整理汇总了Java中com.hp.hpl.jena.rdf.model.Model.add方法的典型用法代码示例。如果您正苦于以下问题:Java Model.add方法的具体用法?Java Model.add怎么用?Java Model.add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.hp.hpl.jena.rdf.model.Model
的用法示例。
在下文中一共展示了Model.add方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: run
import com.hp.hpl.jena.rdf.model.Model; //导入方法依赖的package包/类
@Test
public void run() {
SystemLoader loader = new SystemLoader();
loader.setJdbcURL(db.getJdbcURL());
loader.setUsername(db.getUser());
loader.setMappingFile(mappingFile);
loader.setStartupSQLScript(sqlFile);
loader.setSystemBaseURI(BASE_URI);
if (resultFile == null) {
R2RMLReader reader = loader.getR2RMLReader();
MappingValidator validator = new MappingValidator(
reader.getMapping(), loader.getSQLConnection());
validator.setReport(reader.getReport());
validator.run();
if (!reader.getReport().hasError()) {
fail("Expected validation error");
}
return;
}
Model actualTriples = ModelFactory.createDefaultModel();
actualTriples.add(loader.getModelD2RQ());
Model expectedTriples = FileManager.get().loadModel(resultFile, "N-TRIPLES");
ModelAssert.assertIsomorphic(expectedTriples, actualTriples);
}
示例2: loadDefaultRules
import com.hp.hpl.jena.rdf.model.Model; //导入方法依赖的package包/类
private static Model loadDefaultRules(){
Model rules=ModelFactory.createDefaultModel();
rules.add(SPIN.getModel());
rules.add(SP.getModel());
InputStream in=BimSPARQL.class.getClassLoader().getResourceAsStream("bimsparql/schm.ttl"); //new FileInputStream("IFC2X3_Schema.rdf");
rules.read(in, null,"TTL");
InputStream in2=BimSPARQL.class.getClassLoader().getResourceAsStream("bimsparql/pset.ttl"); //new FileInputStream("IFC2X3_Schema.rdf");
rules.read(in2, null,"TTL");
InputStream in3=BimSPARQL.class.getClassLoader().getResourceAsStream("bimsparql/pdt.ttl"); //new FileInputStream("IFC2X3_Schema.rdf");
rules.read(in3, null,"TTL");
InputStream in4=BimSPARQL.class.getClassLoader().getResourceAsStream("bimsparql/qto.ttl"); //new FileInputStream("IFC2X3_Schema.rdf");
rules.read(in4, null,"TTL");
InputStream in5=BimSPARQL.class.getClassLoader().getResourceAsStream("bimsparql/geom.ttl"); //new FileInputStream("IFC2X3_Schema.rdf");
rules.read(in5, null,"TTL");
InputStream in6=BimSPARQL.class.getClassLoader().getResourceAsStream("bimsparql/spt.ttl"); //new FileInputStream("IFC2X3_Schema.rdf");
rules.read(in6, null,"TTL");
return rules;
}
示例3: runQueryOnInstance
import com.hp.hpl.jena.rdf.model.Model; //导入方法依赖的package包/类
/**
* Runs a given Jena Query on a given instance and adds the inferred triples
* to a given Model.
* @param queryWrapper the wrapper of the CONSTRUCT query to execute
* @param queryModel the query Model
* @param newTriples the Model to write the triples to
* @param instance the instance to run the inferences on
* @param checkContains true to only call add if a Triple wasn't there yet
* @return true if changes were done (only meaningful if checkContains == true)
*/
public static boolean runQueryOnInstance(QueryWrapper queryWrapper, Model queryModel, Model newTriples, Resource instance, boolean checkContains) {
boolean changed = false;
QueryExecution qexec = ARQFactory.get().createQueryExecution(queryWrapper.getQuery(), queryModel);
QuerySolutionMap bindings = new QuerySolutionMap();
bindings.add(SPIN.THIS_VAR_NAME, instance);
Map<String,RDFNode> initialBindings = queryWrapper.getTemplateBinding();
if(initialBindings != null) {
for(String varName : initialBindings.keySet()) {
RDFNode value = initialBindings.get(varName);
bindings.add(varName, value);
}
}
qexec.setInitialBinding(bindings);
Model cm = qexec.execConstruct();
StmtIterator cit = cm.listStatements();
while(cit.hasNext()) {
Statement s = cit.nextStatement();
if(!checkContains || !queryModel.contains(s)) {
changed = true;
newTriples.add(s);
}
}
return changed;
}
示例4: loadIbcData
import com.hp.hpl.jena.rdf.model.Model; //导入方法依赖的package包/类
public static Model loadIbcData(){
Model table=loadModel("Table_705.8.ttl","TTL");
Model tableFunction=loadModel("Table_705.8_Function.ttl","TTL");
Model qudtExpr=loadModel("QudtExpr.ttl","TTL");
Model qudtSpin=loadModel("http://www.qudt.org/qudt/owl/1.0.0/qudt-spin.owl",null);
Model unit=loadModel("http://www.qudt.org/qudt/owl/1.0.0/unit.owl",null);
Model union=ModelFactory.createDefaultModel();
Model spModel = SP.getModel();
Model spinModel = SPIN.getModel();
union.add(table);
union.add(tableFunction);
union.add(qudtExpr);
union.add(qudtSpin);
union.add(unit);
union.add(spModel);
union.add(spinModel);
return union;
}
示例5: bulkUpdate
import com.hp.hpl.jena.rdf.model.Model; //导入方法依赖的package包/类
/**
* Method called to Chunk the triples into N-Sized batches and post to VIVO.
* This is designed to work around / handle errors when posting sets of triples
* over 10,000 to the API.
*
* @param namedGraph String with named graph.
* @param changeModel Jena model with set of changes to sync to store.
* @param changeType Either add or remove.
* @return Boolean true if update was successful.
* @throws IOException
*/
private Boolean bulkUpdate(String namedGraph, Model changeModel, String changeType) throws IOException {
// Temporary model to hold
Model tmpModel = ModelFactory.createDefaultModel();
Integer bSize = Integer.parseInt(batchSize);
// Use an integer to count triples rather than calling size on the model
// during each loop.
Integer size = 0;
StmtIterator iter = changeModel.listStatements();
while (iter.hasNext()) {
Statement stmt = iter.nextStatement(); // get next statement
tmpModel.add(stmt);
size++;
if (size >= bSize) {
// Submit
log.info("Submitting " + size + " triples to " + namedGraph);
submitBatch(tmpModel, namedGraph, changeType);
// Reset the tmp model.
tmpModel.removeAll();
// Reset the counter.
size = 0;
}
}
log.info("model size:" + tmpModel.size());
// Submit the remaining statements, if any.
if (tmpModel.size() > 0) {
submitBatch(tmpModel, namedGraph, changeType);
}
return true;
}
示例6: triplesInvolvingVocabulary
import com.hp.hpl.jena.rdf.model.Model; //导入方法依赖的package包/类
public Model triplesInvolvingVocabulary(Model model) {
Model result = ModelFactory.createDefaultModel();
result.getNsPrefixMap().putAll(model.getNsPrefixMap());
StmtIterator it = model.listStatements();
while (it.hasNext()) {
Statement stmt = it.next();
if (properties.contains(stmt.getPredicate())
|| (stmt.getPredicate().equals(RDF.type) && classes.contains(stmt.getObject()))) {
result.add(stmt);
}
}
return result;
}
示例7: testDump
import com.hp.hpl.jena.rdf.model.Model; //导入方法依赖的package包/类
@Test
public void testDump() {
Model actualTriples = ModelFactory.createDefaultModel();
actualTriples.add(loader.getModelD2RQ());
assertIsomorphic(expectedTriples, actualTriples);
}
示例8: doGet
import com.hp.hpl.jena.rdf.model.Model; //导入方法依赖的package包/类
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws IOException, ServletException {
D2RServer server = D2RServer.fromServletContext(getServletContext());
server.checkMappingFileChanged();
String relativeResourceURI = request.getRequestURI().substring(
request.getContextPath().length()
+ request.getServletPath().length());
// Some servlet containers keep the leading slash, some don't
if (!"".equals(relativeResourceURI)
&& "/".equals(relativeResourceURI.substring(0, 1))) {
relativeResourceURI = relativeResourceURI.substring(1);
}
if (request.getQueryString() != null) {
relativeResourceURI = relativeResourceURI + "?"
+ request.getQueryString();
}
/* Determine service stem, i.e. vocab/ in /[vocab/]data */
int servicePos;
if (-1 == (servicePos = request.getServletPath().indexOf(
"/" + D2RServer.getDataServiceName())))
throw new ServletException("Expected to find service path /"
+ D2RServer.getDataServiceName());
String serviceStem = request.getServletPath().substring(1,
servicePos + 1);
String resourceURI = RequestParamHandler
.removeOutputRequestParam(server.resourceBaseURI(serviceStem)
+ relativeResourceURI);
String documentURL = server.dataURL(serviceStem, relativeResourceURI);
String pageURL = server.pageURL(serviceStem, relativeResourceURI);
String sparqlQuery = "DESCRIBE <" + resourceURI + ">";
QueryExecution qe = QueryExecutionFactory.create(sparqlQuery,
server.dataset());
if (server.getConfig().getPageTimeout() > 0) {
qe.setTimeout(Math.round(server.getConfig().getPageTimeout() * 1000));
}
Model description = qe.execDescribe();
qe.close();
if (description.size() == 0) {
response.sendError(404);
}
if (description.qnameFor(FOAF.primaryTopic.getURI()) == null
&& description.getNsPrefixURI("foaf") == null) {
description.setNsPrefix("foaf", FOAF.NS);
}
Resource resource = description.getResource(resourceURI);
Resource document = description.getResource(documentURL);
document.addProperty(FOAF.primaryTopic, resource);
Statement label = resource.getProperty(RDFS.label);
if (label != null) {
document.addProperty(RDFS.label,
"RDF Description of " + label.getString());
}
server.addDocumentMetadata(description, document);
if (server.getConfig().serveMetadata()) {
// add document metadata from template
Model resourceMetadataTemplate = server.getConfig().getResourceMetadataTemplate(
server, getServletContext());
MetadataCreator resourceMetadataCreator = new MetadataCreator(
server, resourceMetadataTemplate);
description.add(resourceMetadataCreator.addMetadataFromTemplate(
resourceURI, documentURL, pageURL));
Map<String, String> descPrefixes = description.getNsPrefixMap();
descPrefixes.putAll(resourceMetadataTemplate.getNsPrefixMap());
description.setNsPrefixes(descPrefixes);
}
// TODO: Add a Content-Location header
new ModelResponse(description, request, response).serve();
}
示例9: addProperty
import com.hp.hpl.jena.rdf.model.Model; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private void addProperty(IfcdocVO pset,IfcdocVO ifcdocVO, Model model) {
ArrayList<Object> objectList=ifcdocVO.getObjectList();
String propertyName=objectList.get(0).toString();
String psetName=(String)pset.getObjectList().get(0);
String localName=String.valueOf(propertyName.charAt(0)).toLowerCase()+objectList.get(0).toString().substring(1);
// +"_"+pset.getObjectList().get(0).toString().substring(5);
Resource property=model.createResource(PSET+localName+psetName.substring(psetName.indexOf("_")));
property.addProperty(RDF.type, RDF.Property);
property.addProperty(RDF.type, SPIN.MagicProperty);
String propertyType=objectList.get(10).toString().replaceAll("\\s*\\.\\s*", "");
property.addProperty(RDF.type, model.createResource(IFCDOC+propertyType));
property.addProperty(RDFS.subClassOf, SPIN.MagicProperties);
model.add(model.getResource(PSET+pset.getObjectList().get(0)),groups,property);
model.add(property,isGroupedBy,model.getResource(PSET+pset.getObjectList().get(0)));
for (String id:(ArrayList<String>)objectList.get(13)){
IfcdocVO label=linemap.get(Long.parseLong(id.substring(1)));
ArrayList<Object> labelValues=label.getObjectList();
Literal literal=model.createLiteral((String)labelValues.get(2), (String)labelValues.get(0));
property.addLiteral(RDFS.label, literal);
};
property.addLiteral(RDFS.comment, objectList.get(1).toString());
property.addProperty(RDFS.range, model.createResource(IFCOWL+objectList.get(11)));
String domain=pset.getObjectList().get(10).toString();
if(domain.contains(",")){
String[] domains=domain.split(",\\s*");
for (String d:domains){
property.addProperty(RDFS.domain,model.createResource(IFCOWL+d));
}
}else if (domain.contains("/")){
domain=domain.substring(0, domain.indexOf("/"));
property.addProperty(RDFS.domain,model.createResource(IFCOWL+domain));
}
else property.addProperty(RDFS.domain, model.createResource(IFCOWL+domain));
if (propertyType.equals("P_SINGLEVALUE")){
singleValueInference(property,propertyName,psetName);
}
}
示例10: addQuantity
import com.hp.hpl.jena.rdf.model.Model; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private void addQuantity(IfcdocVO pset,IfcdocVO ifcdocVO, Model model) {
ArrayList<Object> objectList=ifcdocVO.getObjectList();
String propertyName=objectList.get(0).toString();
String psetName=(String)pset.getObjectList().get(0);
String localName=String.valueOf(propertyName.charAt(0)).toLowerCase()+objectList.get(0).toString().substring(1);
// +"_"+pset.getObjectList().get(0).toString().substring(5);
Resource property=model.createResource(QTO+localName+psetName.substring(psetName.indexOf("_")));
property.addProperty(RDF.type, RDF.Property);
property.addProperty(RDF.type, SPIN.MagicProperty);
String propertyType=objectList.get(10).toString().replaceAll("\\s*\\.\\s*", "");
property.addProperty(RDF.type, model.createResource(IFCDOC+propertyType));
property.addProperty(RDFS.subClassOf, SPIN.MagicProperties);
model.add(model.getResource(QTO+pset.getObjectList().get(0)),groups,property);
model.add(property,isGroupedBy,model.getResource(QTO+pset.getObjectList().get(0)));
for (String id:(ArrayList<String>)objectList.get(9)){
IfcdocVO label=linemap.get(Long.parseLong(id.substring(1)));
ArrayList<Object> labelValues=label.getObjectList();
Literal literal=model.createLiteral((String)labelValues.get(2), (String)labelValues.get(0));
property.addLiteral(RDFS.label, literal);
};
property.addLiteral(RDFS.comment, objectList.get(1).toString());
// property.addProperty(RDFS.range, model.createResource(IFCOWL+objectList.get(10)));
String domain=pset.getObjectList().get(10).toString();
if(domain.contains(",")){
String[] domains=domain.split(",\\s*");
for (String d:domains){
property.addProperty(RDFS.domain,model.createResource(IFCOWL+d));
}
}else if (domain.contains("/")){
domain=domain.substring(0, domain.indexOf("/"));
property.addProperty(RDFS.domain,model.createResource(IFCOWL+domain));
}
else property.addProperty(RDFS.domain, model.createResource(IFCOWL+domain));
singleValueInference(property,propertyName,propertyType);
}
示例11: extract
import com.hp.hpl.jena.rdf.model.Model; //导入方法依赖的package包/类
public static void extract(Model m,String name){
Property groups=m.createProperty("http://www.buildingsmart-tech.org/ifc/IFC4/final#groups");
Property isGroupedBy=m.createProperty("http://www.buildingsmart-tech.org/ifc/IFC4/final#isGroupedBy");
Resource SingleValue=m.createResource("http://www.buildingsmart-tech.org/ifc/IFC4/final#P_SINGLEVALUE");
Model vocabulary=ModelFactory.createDefaultModel();
StmtIterator stmt1=m.listStatements(null, RDFS.comment,(String)null);
StmtIterator stmt2=m.listStatements(null,RDFS.domain,(RDFNode)null);
StmtIterator stmt3=m.listStatements(null,RDFS.range,(RDFNode)null);
StmtIterator stmt4=m.listStatements(null, RDF.type, RDF.Property);
StmtIterator stmt6=m.listStatements(null, RDFS.label, (String)null);
StmtIterator stmt8=m.listStatements(null, groups, (RDFNode)null);
StmtIterator stmt9=m.listStatements(null, isGroupedBy, (RDFNode)null);
vocabulary.add(stmt1);
vocabulary.add(stmt2);
vocabulary.add(stmt3);
vocabulary.add(stmt4);
vocabulary.add(stmt6);
vocabulary.add(stmt8);
vocabulary.add(stmt9);
m.remove(vocabulary);
StmtIterator stmt7=m.listStatements(null, RDF.type, (RDFNode)null);
List<Statement> ss=new ArrayList<Statement>();
while(stmt7.hasNext()){
Statement s=stmt7.next();
if(s.getObject().asResource().getURI().startsWith("http://www.buildingsmart-tech.org/ifc/IFC4/final")){
ss.add(s);
}
}
m.remove(ss);
try {
OutputStream voc=new FileOutputStream("C:\\users\\chi\\desktop\\output\\"+name+".ttl");
OutputStream rule=new FileOutputStream("C:\\users\\chi\\desktop\\output\\"+name+"_rule.ttl");
vocabulary.setNsPrefixes(m.getNsPrefixMap());
vocabulary.write(voc,"TTL");
m.write(rule,"TTL");
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}