本文整理匯總了Java中com.hp.hpl.jena.rdf.model.ModelFactory類的典型用法代碼示例。如果您正苦於以下問題:Java ModelFactory類的具體用法?Java ModelFactory怎麽用?Java ModelFactory使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
ModelFactory類屬於com.hp.hpl.jena.rdf.model包,在下文中一共展示了ModelFactory類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: initializeCategories
import com.hp.hpl.jena.rdf.model.ModelFactory; //導入依賴的package包/類
public Set<String> initializeCategories() {
Model model = ModelFactory.createDefaultModel();
model.read("/home/zwicklbauer/HDTGeneration/skos_categories_en.nt");
StmtIterator it = model.listStatements();
Set<String> set = new HashSet<String>();
System.out.println("Los gehts");
while (it.hasNext()) {
Statement s = it.next();
Resource r = s.getSubject();
Property p = s.getPredicate();
RDFNode n = s.getObject();
if (p.getURI().equalsIgnoreCase(
"http://www.w3.org/2004/02/skos/core#broader")
&& n.isResource()) {
Resource target = n.asResource();
if(!hasSubCategory(target.getURI()))
set.add(target.getURI());
if(!hasSubCategory(r.getURI()))
set.add(r.getURI());
}
}
return set;
}
示例2: 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);
}
示例3: run
import com.hp.hpl.jena.rdf.model.ModelFactory; //導入依賴的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);
}
示例4: 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");
}
示例5: 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;
}
示例6: reload
import com.hp.hpl.jena.rdf.model.ModelFactory; //導入依賴的package包/類
private void reload() {
loader.getMapping().connect();
GraphD2RQ graph = loader.getGraphD2RQ();
datasetGraph = DatasetGraphFactory.createOneGraph(graph);
defaultModel = ModelFactory.createModelForGraph(datasetGraph.getDefaultGraph());
hasTruncatedResults = false;
for (Database db: loader.getMapping().databases()) {
if (db.getResultSizeLimit() != Database.NO_LIMIT) {
hasTruncatedResults = true;
}
}
if (autoReload) {
lastModified = watchedFile.lastModified();
lastReload = System.currentTimeMillis();
}
}
示例7: 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());
database.useConnectedDB(new DummyDB());
this.mapping.addDatabase(this.database);
employees = createClassMap("http://test/[email protected]@[email protected]@");
employees.addAlias("employees AS e");
employees.addJoin("e.ID = foo.bar");
employees.addCondition("e.status = 'active'");
managerBridge = createPropertyBridge(employees, "http://terms.example.org/manager");
managerBridge.addAlias("e AS m");
managerBridge.setRefersToClassMap(this.employees);
managerBridge.addJoin("e.manager = m.ID");
cities = createClassMap("http://test/[email protected]@[email protected]@");
citiesTypeBridge = createPropertyBridge(cities, RDF.type.getURI());
citiesTypeBridge.setConstantValue(model.createResource("http://terms.example.org/City"));
citiesNameBridge = createPropertyBridge(cities, "http://terms.example.org/name");
citiesNameBridge.setColumn("c.name");
countries = createClassMap("http://test/countries/@@[email protected]@");
countries.setContainsDuplicates(true);
countriesTypeBridge = createPropertyBridge(countries, RDF.type.getURI());
countriesTypeBridge.setConstantValue(model.createResource("http://terms.example.org/Country"));
}
示例8: toRdf
import com.hp.hpl.jena.rdf.model.ModelFactory; //導入依賴的package包/類
/**
* Convert a PhenoPacket to RDF triples using the JSON-LD context
*
* @param packet
* @param base
* URI base for generated RDF; if `null` a UUID-based base will
* be used
* @return model containing RDF triples
* @throws JsonLdError
* @throws JsonProcessingException
*/
public static Model toRdf(PhenoPacket packet, String base)
throws JsonLdError, JsonProcessingException {
PhenoPacket packetWithContext;
if (packet.getContext() == null) {
packetWithContext = PhenoPacket.newBuilder(packet)
.context(ContextUtil.defaultContextURI)
.build();
} else {
packetWithContext = packet;
}
Model rdfModel = ModelFactory.createDefaultModel();
StringReader reader = new StringReader(
JsonGenerator.render(packetWithContext));
String baseToUse;
if (base != null) {
baseToUse = base;
} else {
String uuid = UUID.randomUUID().toString();
baseToUse = "http://phenopackets.org/local/" + uuid + "/";
}
RDFDataMgr.read(rdfModel, reader, baseToUse, Lang.JSONLD);
return rdfModel;
}
示例9: loadDefaultRules
import com.hp.hpl.jena.rdf.model.ModelFactory; //導入依賴的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;
}
示例10: loadDefaultModel
import com.hp.hpl.jena.rdf.model.ModelFactory; //導入依賴的package包/類
public static OntModel loadDefaultModel(){
InputStream in = BodyGeometryTest.class.getClassLoader()
.getResourceAsStream("Duplex_A_20110505.ttl");
Model model=ModelFactory.createDefaultModel();
model.read(in,null,"TTL");
InputStream ins = BodyGeometryTest.class.getClassLoader()
.getResourceAsStream("IFC2X3_TC1.ttl");
InputStream input = BodyGeometryTest.class.getClassLoader()
.getResourceAsStream("Duplex_A_20110505_geometry.ttl");
Model geometryModel=ModelFactory.createDefaultModel();
geometryModel.read(input,null,"TTL");
Model schema=ModelFactory.createDefaultModel();
schema.read(ins,null,"TTL");
try {
BimSPARQL.init(model,geometryModel);
} catch (ClassNotFoundException | IOException | ParserConfigurationException | SAXException
| URISyntaxException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
OntModel ontology=ModelFactory.createOntologyModel();
ontology.add(schema);
ontology.add(model);
ontology.add(geometryModel);
return ontology;
}
示例11: loadIbcData
import com.hp.hpl.jena.rdf.model.ModelFactory; //導入依賴的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;
}
示例12: sendRequest
import com.hp.hpl.jena.rdf.model.ModelFactory; //導入依賴的package包/類
/***************************************************************************
* Private Methods - Handle Translation
**************************************************************************/
private Model sendRequest(HttpServletRequest req, String url)
throws ResponseThrowable
{
HttpClient client = new HttpClient();
GetMethod method = new GetMethod(url);
method.setRequestHeader("Accept-Encoding", "gzip");
method.setRequestHeader("Accept" , _format.getMimetype());
InputStream is = null;
try {
int rspCode = client.executeMethod(method);
if ( rspCode != 200 ) { throw new ResponseThrowable(rspCode); }
is = getInputStream(method);
Model m = ModelFactory.createDefaultModel();
m.read(is, null, _format.getJenaFormat().getLang().getLabel());
return m;
}
catch (RiotException | IOException e) {
throw new ResponseThrowable(e, 502);
}
finally { IOUtils.closeQuietly(is); method.releaseConnection(); }
}
示例13: writeUserEntries
import com.hp.hpl.jena.rdf.model.ModelFactory; //導入依賴的package包/類
/**
* Writes the user entities to rdf
*/
private static OntModel writeUserEntries() {
OntModel model = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
try {
thewebsemantic.Bean2RDF writer = new Bean2RDF(model);
InitialContext ic = new InitialContext();
UserService userService = (UserService) ic.lookup("java:module/UserService");
List<User> users = userService.getAll();
for (User u : users) {
writer.save(u);
}
} catch (Exception e) {
e.printStackTrace();
}
return model;
}
示例14: process
import com.hp.hpl.jena.rdf.model.ModelFactory; //導入依賴的package包/類
public void process(File src, File all, File dst, File enrich) throws IOException
{
Model m = ModelFactory.createDefaultModel();
loadFiles(src, ".xml", m);
storeAsEDM(m, all);
_type = m.getProperty(RDF_TYPE);
_prefLabel = m.getProperty(SKOS_PREF_LABEL);
_foafName = m.getProperty(FOAF_NAME);
Resource pcho = m.getResource(EDM_PROVIDEDCHO);
CSVWriter printer = new CSVWriter(enrich, CSVFormat.EXCEL);
printer.start();
try {
enrichImpl(m.listSubjectsWithProperty(_type, pcho), printer);
}
finally {
printer.end();
}
storeAsEDM(m, dst);
new CHOAnalysis().analyse(dst);
}
示例15: merge
import com.hp.hpl.jena.rdf.model.ModelFactory; //導入依賴的package包/類
public void merge(File src, File dst) throws IOException
{
Model m = ModelFactory.createDefaultModel();
m.setNsPrefix("cc", "http://creativecommons.org/ns#");
m.setNsPrefix("dc", "http://purl.org/dc/elements/1.1/");
m.setNsPrefix("dcterms", "http://purl.org/dc/terms/");
m.setNsPrefix("edm", "http://www.europeana.eu/schemas/edm/");
m.setNsPrefix("foaf", "http://xmlns.com/foaf/0.1/");
m.setNsPrefix("odrl", "http://www.w3.org/ns/odrl/2/");
m.setNsPrefix("ore", "http://www.openarchives.org/ore/terms/");
m.setNsPrefix("owl", "http://www.w3.org/2002/07/owl#");
m.setNsPrefix("rdaGr2", "http://rdvocab.info/ElementsGr2/");
m.setNsPrefix("skos", "http://www.w3.org/2004/02/skos/core#");
m.setNsPrefix("wgs84_pos", "http://www.w3.org/2003/01/geo/wgs84_pos#");
m.setNsPrefix("xsi", "http://www.w3.org/2001/XMLSchema-instance");
m.setNsPrefix("xml", "http://www.w3.org/XML/1998/namespace");
merge(src, m);
//store(m, dst, "RDF/XML-ABBREV");
store(m, dst, "RDF/XML");
}