本文整理匯總了Java中com.hp.hpl.jena.rdf.model.ModelFactory.createDefaultModel方法的典型用法代碼示例。如果您正苦於以下問題:Java ModelFactory.createDefaultModel方法的具體用法?Java ModelFactory.createDefaultModel怎麽用?Java ModelFactory.createDefaultModel使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.hp.hpl.jena.rdf.model.ModelFactory
的用法示例。
在下文中一共展示了ModelFactory.createDefaultModel方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: parse
import com.hp.hpl.jena.rdf.model.ModelFactory; //導入方法依賴的package包/類
/**
* Parse RDF input as string
*
* @param input RDF values as String
* @return an {@link Request} object which contains information about latitude, longitude and date
* @throws IllegalStateException if RDF is not literal
* @throws NullPointerException if input is null
*/
public static Request parse(String input) {
Objects.requireNonNull(input);
Model model = ModelFactory.createDefaultModel();
model.read(new ByteArrayInputStream(input.getBytes()), null, "TURTLE");
Map<String, Object> map = new HashMap<>();
model.listStatements().forEachRemaining(statement -> {
RDFNode rdfNode = statement.getObject();
if (rdfNode.isLiteral()) {
try {
map.put(statement.getPredicate().getLocalName(), statement.getObject().asLiteral().getValue());
} catch (Exception e) {
LOGGER.error("RDF statement is not literal");
throw new IllegalStateException(e.getMessage());
}
}
});
model.close();
return getDataFromMap(map);
}
示例2: setUp
import com.hp.hpl.jena.rdf.model.ModelFactory; //導入方法依賴的package包/類
public void setUp() {
this.model = ModelFactory.createDefaultModel();
this.mapping = new Mapping();
this.database = new Database(this.model.createResource());
this.mapping.addDatabase(this.database);
concept = createClassMap("http://example.com/concept#@@[email protected]@");
conceptTypeBridge = createPropertyBridge(concept, RDF.type.getURI());
conceptTypeBridge.setConstantValue(model.createResource("http://www.w3.org/2004/02/skos/core#Concept"));
collection = createConstantClassMap("http://example.com/collection#MyConceptCollection");
collectionTypeBridge = createPropertyBridge(collection, RDF.type.getURI());
collectionTypeBridge.setConstantValue(model.createResource("http://www.w3.org/2004/02/skos/core#Collection"));
memberBridge = createPropertyBridge(collection, "http://www.w3.org/2004/02/skos/core#member");
memberBridge.setRefersToClassMap(concept);
memberBridge.addCondition("c.foo = 1");
}
示例3: getTestListFromManifest
import com.hp.hpl.jena.rdf.model.ModelFactory; //導入方法依賴的package包/類
public static Collection<Object[]> getTestListFromManifest(String manifestFileURL) {
// We'd like to use FileManager.loadModel() but it doesn't work on jar: URLs
// Model m = FileManager.get().loadModel(manifestFileURL);
Model m = ModelFactory.createDefaultModel();
m.read(manifestFileURL, "TURTLE");
IRI baseIRI = D2RQTestUtil.createIRI(m.getNsPrefixURI("base"));
ResultSet rs = QueryExecutionFactory.create(TEST_CASE_LIST, m).execSelect();
List<Object[]> result = new ArrayList<Object[]>();
while (rs.hasNext()) {
QuerySolution qs = rs.next();
Resource mapping = qs.getResource("mapping");
Resource schema = qs.getResource("schema");
// if (!mapping.getLocalName().equals("constant-object.ttl")) continue;
QueryExecution qe = QueryExecutionFactory.create(TEST_CASE_TRIPLES, m);
qe.setInitialBinding(qs);
Model expectedTriples = qe.execConstruct();
result.add(new Object[]{baseIRI.relativize(mapping.getURI()).toString(), mapping.getURI(),
schema.getURI(), expectedTriples});
}
return result;
}
示例4: loadModel
import com.hp.hpl.jena.rdf.model.ModelFactory; //導入方法依賴的package包/類
public static boolean loadModel(Model m, String url)
{
String sContent = getRDF(url);
if ( sContent == null ) { return false; }
Model mTemp = ModelFactory.createDefaultModel();
try {
mTemp.read(new StringReader(sContent), url, "RDF/XML");
}
catch (Exception e) {
System.err.println("error parsing: " + url + ", error: " + e.getMessage());
return false;
}
m.add(mTemp);
return true;
}
示例5: importModelFromSingleFile
import com.hp.hpl.jena.rdf.model.ModelFactory; //導入方法依賴的package包/類
private void importModelFromSingleFile(File file, String lang) {
Model m = ModelFactory.createDefaultModel();
try {
InputStream s = new FileInputStream(file);
m.read(s, null);
this.addModel(m, file.getName());
logger.info("The model " + file.getPath() + " successfully imported to repository");
} catch (Throwable t) {
logger.error("Error reading the model file!", t);
return;
}
}
示例6: main
import com.hp.hpl.jena.rdf.model.ModelFactory; //導入方法依賴的package包/類
public static void main(String[] args) throws JSONException, KarmaException, IOException {
Options options = createCommandLineOptions();
CommandLine cl = CommandLineArgumentParser.parse(args, options, GenerateContextFromModel.class.getSimpleName());
if(cl == null)
{
return;
}
String fileName = (String) cl.getOptionValue("modelpath");
String output = (String) cl.getOptionValue("outputfile");
if (fileName == null) {
System.out.println("No model file specified!");
return;
}
if (output == null) {
output = fileName + ".json";
}
File file = new File(fileName);
Model model = ModelFactory.createDefaultModel();
InputStream s = new FileInputStream(file);
model.read(s, null, "TURTLE");
JSONObject top = new ContextGenerator(model, true).generateContext();
PrintWriter pw = new PrintWriter(output);
pw.println(top.toString(4));
pw.close();
}
示例7: readFrom
import com.hp.hpl.jena.rdf.model.ModelFactory; //導入方法依賴的package包/類
@Override
public Model readFrom(Class<Model> type, Type genericType, Annotation[] annotations,
MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream)
throws IOException, WebApplicationException {
Model model = ModelFactory.createDefaultModel();
model.read(entityStream, null);
return model;
}
示例8: loadMetadataTemplate
import com.hp.hpl.jena.rdf.model.ModelFactory; //導入方法依賴的package包/類
public static Model loadMetadataTemplate(InputStream is) {
try {
Model tplModel = ModelFactory.createDefaultModel();
tplModel.read(is, "about:prefix:", "TTL");
return tplModel;
} catch (JenaException e) {
// ignore
}
return null;
}
示例9: main
import com.hp.hpl.jena.rdf.model.ModelFactory; //導入方法依賴的package包/類
public static void main(String[] args) throws FileNotFoundException{
Model model=ModelFactory.createDefaultModel();
InputStream in=new FileInputStream("BimSPARQL_example.ttl");
model.read(in,null,"TTL");
String query=prefixes+"SELECT ?s\n"+
"WHERE{?s ?p ?o .}";
Query q = QueryFactory.create(query);
QueryExecution qe = QueryExecutionFactory.create(q, model);
ResultSet qresults = qe.execSelect();
ResultSetFormatter.out(qresults);
}
示例10: loadModel
import com.hp.hpl.jena.rdf.model.ModelFactory; //導入方法依賴的package包/類
public static Model loadModel(String url,String lang){
Model model=ModelFactory.createDefaultModel();
if(lang==null){
model.read(url);
}else{
InputStream in=FireSeparationDistance.class.getClassLoader().getResourceAsStream(url);
model.read(in,null,lang);
}
return model;
}
示例11: bulkUpdate
import com.hp.hpl.jena.rdf.model.ModelFactory; //導入方法依賴的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;
}
示例12: createModel
import com.hp.hpl.jena.rdf.model.ModelFactory; //導入方法依賴的package包/類
private Model createModel() {
Model model = ModelFactory.createDefaultModel();
String NS = "http://www.computas.no/zebra/";
model.setNsPrefix("", NS);
model.setNsPrefix("xsd", "http://www.w3.org/2001/XMLSchema#");
//TODO
return model;
}
示例13: createModel
import com.hp.hpl.jena.rdf.model.ModelFactory; //導入方法依賴的package包/類
private Model createModel() {
Model model = ModelFactory.createDefaultModel();
String NS = "http://www.computas.no/zebra/";
model.setNsPrefix("", NS);
model.setNsPrefix("xsd", "http://www.w3.org/2001/XMLSchema#");
Resource subject = model.createResource(NS + "Joe");
Property predicate = model.createProperty(NS + "hasSentMessage");
String object = "Hello World!";
subject.addProperty(predicate, object, XSDDatatype.XSDstring);
return model;
}
示例14: loadModel
import com.hp.hpl.jena.rdf.model.ModelFactory; //導入方法依賴的package包/類
public static Model loadModel(String filenameOrURL, String baseIRI, String lang) {
if (!filenameOrURL.toLowerCase().startsWith("jar:")) {
return FileManager.get().loadModel(filenameOrURL, baseIRI, lang);
}
Model result = ModelFactory.createDefaultModel();
result.read(filenameOrURL, baseIRI, lang);
return result;
}
示例15: getResult
import com.hp.hpl.jena.rdf.model.ModelFactory; //導入方法依賴的package包/類
public List<String> getResult(InputStream in, String query){
Model model=ModelFactory.createDefaultModel();
model.read(in,null,"TTL");
Query q = QueryFactory.create(query);
QueryExecution qe = QueryExecutionFactory.create(q, model);
ResultSet qresults = qe.execSelect();
List<QuerySolution> solutions=ResultSetFormatter.toList(qresults);
List<String> results=new ArrayList<String>();
for(QuerySolution qs:solutions){
results.add(qs.toString());
}
return results;
}