本文整理汇总了Java中org.apache.jena.rdf.model.ModelFactory类的典型用法代码示例。如果您正苦于以下问题:Java ModelFactory类的具体用法?Java ModelFactory怎么用?Java ModelFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ModelFactory类属于org.apache.jena.rdf.model包,在下文中一共展示了ModelFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createModel
import org.apache.jena.rdf.model.ModelFactory; //导入依赖的package包/类
@Override
protected Model createModel(String dbId) {
Model model = null;
try {
File hdtFile = getHDTPath(dbId).toFile();
if (hdtFile.exists()) {
boolean useIdx = useIndex(dbId);
String hdtFilePathStr = hdtFile.getAbsolutePath();
logger.info(marker, "Loading '{}', useIndex={}", hdtFilePathStr, useIdx);
HDT hdt = useIdx ? HDTManager.mapIndexedHDT(hdtFilePathStr, null) : HDTManager.loadHDT(hdtFilePathStr, null);
HDTGraph graph = new HDTGraph(hdt);
model = ModelFactory.createModelForGraph(graph);
return model;
}
throw new FileNotFoundException("HDT file not found: '" + hdtFile + "'");
} catch (Exception e) {
throw new StarGraphException(e);
}
finally {
if (model == null) {
logger.error(marker, "No Graph Model instantiated for {}", dbId);
}
}
}
示例2: createObject
import org.apache.jena.rdf.model.ModelFactory; //导入依赖的package包/类
/**
* Creates a new object.
*
* This originally used application/octet-stream;qs=1001 as a workaround
* for JERSEY-2636, to ensure requests without a Content-Type get routed here.
* This qs value does not parse with newer versions of Jersey, as qs values
* must be between 0 and 1. We use qs=1.000 to mark where this historical
* anomaly had been.
*
* @param contentDisposition the content Disposition value
* @param requestContentType the request content type
* @param slug the slug value
* @param requestBodyStream the request body stream
* @param link the link value
* @param digest the digest header
* @return 201
* @throws InvalidChecksumException if invalid checksum exception occurred
* @throws IOException if IO exception occurred
* @throws MalformedRdfException if malformed rdf exception occurred
*/
@POST
@Consumes({MediaType.APPLICATION_OCTET_STREAM + ";qs=1.000", WILDCARD})
@Produces({TURTLE_WITH_CHARSET + ";qs=1.0", JSON_LD + ";qs=0.8",
N3_WITH_CHARSET, N3_ALT2_WITH_CHARSET, RDF_XML, NTRIPLES, TEXT_PLAIN_WITH_CHARSET,
TURTLE_X, TEXT_HTML_WITH_CHARSET, "*/*"})
public Response createObject(@HeaderParam(CONTENT_DISPOSITION) final ContentDisposition contentDisposition,
@HeaderParam(CONTENT_TYPE) final MediaType requestContentType,
@HeaderParam("Slug") final String slug,
@ContentLocation final InputStream requestBodyStream,
@HeaderParam(LINK) final String link,
@HeaderParam("Digest") final String digest)
throws InvalidChecksumException, IOException, MalformedRdfException {
LOGGER.info("POST: {}", externalPath);
final ContainerService containerService = getContainerService();
final URI resourceUri = createFromPath(externalPath);
//check that resource exists
if (!containerService.exists(resourceUri)) {
if (!isRoot(resourceUri)) {
return status(NOT_FOUND).build();
} else {
createRoot();
}
}
final String newResourceName = slug == null ? UUID.randomUUID().toString() : slug;
final String resourcePath = (isRoot(resourceUri) ? "" : resourceUri.getPath());
final URI newResourceUri = createFromPath(resourcePath + "/" + newResourceName);
final Container container = containerService.findOrCreate(newResourceUri);
final Model model = ModelFactory.createDefaultModel();
model.read(requestBodyStream, container.getIdentifier().toString(), "TTL");
final Stream<Triple> triples = model.listStatements().toList().stream().map(Statement::asTriple);
container.updateTriples(triples);
return created(toExternalURI(container.getIdentifier(), headers)).build();
}
示例3: createModel
import org.apache.jena.rdf.model.ModelFactory; //导入依赖的package包/类
@Override
protected Model createModel(String dbId) {
File ntriplesFile = getNTriplesPath(dbId).toFile();
if (!ntriplesFile.exists()) {
logger.warn(marker, "Can't find NT file {}", ntriplesFile);
} else {
try (InputStream is = new FileInputStream(ntriplesFile)) {
Model model = ModelFactory.createDefaultModel();
model.read(is, null, "N-TRIPLES");
return model;
} catch (Exception e) {
throw new StarGraphException(e);
}
}
return null;
}
示例4: setUp
import org.apache.jena.rdf.model.ModelFactory; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
model = ModelFactory.createDefaultModel();
model.read("Playpen2.ttl", "TTL");
prop1 = model.createProperty("http://foo.com/foo");
prop2 = model.createProperty("http://foo.com/bar");
prop3 = model.createProperty("http://foo.com/fasel");
prop4 = model.createProperty("http://foo.com/fase2");
prop5 = model.createProperty("http://foo.com/thisUri");
prop6 = model.createProperty("http://foo.com/stringy");
newConceptRes = model.createResource("http://example.com/Playpen2#newConcept");
foobarFooRes = model.createResource("http://example/com/Playpen2#foobarFoo");
}
开发者ID:Smartlogic-Semaphore-Limited,项目名称:Java-APIs,代码行数:17,代码来源:DiffToSparqlInsertUpdateBuilderTests.java
示例5: testLocalDiff
import org.apache.jena.rdf.model.ModelFactory; //导入依赖的package包/类
@Test
public void testLocalDiff() throws Exception {
Model firstModel = ModelFactory.createDefaultModel();
firstModel.read("Playpen2.ttl", "TTL");
Model secondModel = ModelFactory.createDefaultModel();
secondModel.add(firstModel);
Resource res1 = secondModel.createResource(resIri1);
res1.addProperty(RDF.type, SKOS.Concept);
client.setCurrentModel(firstModel);
client.setPendingModel(secondModel);
assertEquals(firstModel, client.getCurrentModel());
assertEquals(secondModel, client.getPendingModel());
RDFDifference diff = client.getBatchDiff();
assertTrue(diff.getInLeftOnly().size() == 0);
assertTrue(diff.getInRightOnly().size() == 1);
assertFalse(diff.getInLeftOnly().containsResource(res1));
assertFalse(diff.getInLeftOnly().contains(res1, RDF.type, SKOS.Concept));
assertTrue(diff.getInRightOnly().containsResource(res1));
assertTrue(diff.getInRightOnly().contains(res1, RDF.type, SKOS.Concept));
}
示例6: createModel
import org.apache.jena.rdf.model.ModelFactory; //导入依赖的package包/类
private Model createModel(Logger logger) throws IOException {
LoggingUtils.configureSilentLog4J();
Model model = ModelFactory.createDefaultModel();
model.setNsPrefixes(PrefixMapping.Standard);
model.setNsPrefix("xsd", "http://www.w3.org/2001/XMLSchema#");
model.setNsPrefix("skos", "http://www.w3.org/2004/02/skos/core#");
model.setNsPrefix("oboInOwl", "http://www.geneontology.org/formats/oboInOwl#");
model.setNsPrefixes(prefixes);
for (InputStream is : Iterators.loop(source.getInputStreams())) {
logger.info("loading model from: " + source.getStreamName(is));
// System.err.println("is = " + is);
// model.read(is, null, Lang.RDFXML.toString());
RDFDataMgr.read(model, is, Lang.RDFXML);
}
return model;
}
示例7: getJenaModel
import org.apache.jena.rdf.model.ModelFactory; //导入依赖的package包/类
private Model getJenaModel(@NonNull org.eclipse.rdf4j.model.Model model) {
Model jenaModel = ModelFactory.createDefaultModel();
java.util.Iterator<org.eclipse.rdf4j.model.Statement> iterator = model.iterator();
while (iterator.hasNext()) {
org.eclipse.rdf4j.model.Statement rdf4jStatement = iterator.next();
// create resource / subject
Resource resource = rdf4jResourceToJenaResource(jenaModel, rdf4jStatement.getSubject());
// create property / predicate
Property property =
rdf4jPropertyToJenaProperty(jenaModel, (SimpleIRI) rdf4jStatement.getPredicate());
// create rdfnode / object
RDFNode node = rdf4jValueToJenaRdfNode(jenaModel, rdf4jStatement.getObject());
Statement statement = ResourceFactory.createStatement(resource, property, node);
jenaModel.add(statement);
}
return jenaModel;
}
示例8: main
import org.apache.jena.rdf.model.ModelFactory; //导入依赖的package包/类
public static void main(String[] args) throws IOException {
PropertyConfigurator.configure("log4j.info");
BufferedReader reader = new BufferedReader(new FileReader(args[0]));
FileOutputStream out = new FileOutputStream(new File("/usr/local/RAID/geonames.nt"));
String buffer = null;
int count = 0;
while ((buffer = reader.readLine()) != null) {
if (++count % 2 == 0) {
logger.debug("processing xml: " + buffer);
Model model = ModelFactory.createDefaultModel() ;
model.read(new StringReader(buffer), null, "RDF/XML");
model.write(out, "N-TRIPLE");
} else {
logger.info("skipping: " + buffer);
}
}
reader.close();
}
示例9: makeSampleModel
import org.apache.jena.rdf.model.ModelFactory; //导入依赖的package包/类
private static Model makeSampleModel() {
String BASE = "http://example/";
Model model = ModelFactory.createDefaultModel();
model.setNsPrefix("", BASE);
Resource r1 = model.createResource(BASE + "r1");
Resource r2 = model.createResource(BASE + "r2");
Property p1 = model.createProperty(BASE + "p");
Property p2 = model.createProperty(BASE + "p2");
RDFNode v1 = model.createTypedLiteral("1", XSDDatatype.XSDinteger);
RDFNode v2 = model.createTypedLiteral("2", XSDDatatype.XSDinteger);
r1.addProperty(p1, v1).addProperty(p1, v2);
r1.addProperty(p2, v1).addProperty(p2, v2);
r2.addProperty(p1, v1).addProperty(p1, v2);
return model;
}
示例10: main
import org.apache.jena.rdf.model.ModelFactory; //导入依赖的package包/类
public static void main(String[] args) throws IOException {
File f = new File("/Users/rosenc/Documents/business/[2015]icbms/json_sample1.txt");
BufferedReader br = new BufferedReader(new FileReader(f));
String line = null;
String s = "";
while ((line = br.readLine()) != null) {
s = s + line + "\n";
}
System.out.println(s);
Gson gson = new Gson();
OneM2MContentInstanceDTO cont = gson.fromJson(s, OneM2MContentInstanceDTO.class);
OneM2MContentInstanceMapper mapper = new OneM2MContentInstanceMapper(cont);
Model model = ModelFactory.createDefaultModel();
model.add(mapper.from());
System.out.println("content type ; " + mapper.getContentType());
// 스트링 변환부분
RDFDataMgr.write(System.out, model, RDFFormat.NTRIPLES);
// System.out.println(mapper.getTypedContent("2k42kk"));
// mapper.getTypedContent("2.4");
}
示例11: main
import org.apache.jena.rdf.model.ModelFactory; //导入依赖的package包/类
public static void main(String[] args) {
String sample = " { \"_id\" : ObjectId(\"561e1e1e1ee82041fac258b6\"), \"rn\" : \"SAE_0\", \"ty\" : 2, \"ri\" : \"SAE_0\", \"pi\" : \"herit-in\", \"lbl\" : [ \"home1\", \"home_service\" ], \"et\" : \"20151203T122321\", \"at\" : [ \"//onem2m.hubiss.com/cse1\", \"//onem2m.hubiss.com/cse2\" ], \"aa\" : [ \"poa\", \"apn\" ], \"apn\" : \"onem2mPlatformAdmin\", \"api\" : \"NHeritAdmin\", \"aei\" : \"/SAE_0\", \"poa\" : [ \"10.101.101.111:8080\" ], \"rr\" : false, \"_uri\" : \"/herit-in/herit-cse/SAE_0\", \"ct\" : \"20151014T181926\", \"lt\" : \"20151014T181926\" }";
Gson gson = new Gson();
OneM2MAEDTO cont = gson.fromJson(sample, OneM2MAEDTO.class);
System.out.println(cont);
OneM2MAEMapper mapper = new OneM2MAEMapper(cont);
Model model = ModelFactory.createDefaultModel();
model.add(mapper.from());
//스트링 변환부분
RDFDataMgr.write(System.out, model, RDFFormat.NTRIPLES);
// gooper
if(! model.isClosed()) {
model.close();
}
if(model != null) {
model = null;
}
}
示例12: main
import org.apache.jena.rdf.model.ModelFactory; //导入依赖的package包/类
public static void main(String[] args) {
String sample = "{ \"_id\" : ObjectId(\"560c9d741ee8203c53a63569\"), \"rn\" : \"CONTENT_INST_5\", \"ty\" : 4, \"ri\" : \"CONTENT_INST_5\", \"pi\" : \"CONTAINER_37\", \"lbl\" : [ \"cnt-switch\" ], \"cr\" : \"C_AE-D-GASLOCK1004\", \"cnf\" : \"text/plain:0\", \"cs\" : 3, \"con\" : \"Off\", \"_uri\" : \"/herit-in/herit-cse/ae-gaslock1004/cnt-switch/CONTENT_INST_5\", \"ct\" : \"20151001T114156\", \"lt\" : \"20151001T114156\" , \"or\":\"http://www.iotoasis.org/ontology/StateCondition\" }";
Gson gson = new Gson();
OneM2MContentInstanceDTO cont = gson.fromJson(sample, OneM2MContentInstanceDTO.class);
System.out.println(cont);
OneM2MContentInstanceMapper mapper = new OneM2MContentInstanceMapper(cont);
Model model = ModelFactory.createDefaultModel();
model.add(mapper.from());
// 스트링 변환부분
RDFDataMgr.write(System.out, model, RDFFormat.NTRIPLES);
// gooper
if(! model.isClosed()) {
model.close();
}
if(model != null) {
model = null;
}
}
示例13: test
import org.apache.jena.rdf.model.ModelFactory; //导入依赖的package包/类
@Test
public void test() {
Model model = ModelFactory.createDefaultModel();
InputStream is = this.getClass().getClassLoader().getResourceAsStream(GRAPH_FILE);
model.read(is, null, "N3");
IOUtils.closeQuietly(is);
GraphCreator creator = new GraphCreator();
ColouredGraph graph = creator.processModel(model);
Assert.assertNotNull(graph);
NumberOfTrianglesMetric metric = new NumberOfTrianglesMetric();
double countedTriangles = metric.apply(graph);
Assert.assertEquals(EXPECTED_TRIANGLES, countedTriangles, 0.000001);
}
示例14: test
import org.apache.jena.rdf.model.ModelFactory; //导入依赖的package包/类
@Test
public void test() {
Model model = ModelFactory.createDefaultModel();
InputStream is = this.getClass().getClassLoader().getResourceAsStream(GRAPH_FILE);
model.read(is, null, "N3");
IOUtils.closeQuietly(is);
GraphCreator creator = new GraphCreator();
ColouredGraph graph = creator.processModel(model);
//System.out.println("matrix: " +graph.getGraph().getAdjacencyMatrix());
// System.out.println("graph.getInNeighborhoodsArray()" +Arrays.deepToString(graph.getInNeighborhoodsArray()));
// System.out.println("graph.getOutNeighborhoodsArray()" +Arrays.deepToString(graph.getOutNeighborhoodsArray()));
// Commented out the following line since HITS is missing.
// new HITS(graph);
// graph.getGraph().display();
// try {
// Thread.sleep(100000);
// } catch (InterruptedException ex) {
// Logger.getLogger(HITSTest.class.getName()).log(Level.SEVERE, null, ex);
// }
}
示例15: test
import org.apache.jena.rdf.model.ModelFactory; //导入依赖的package包/类
@Test
public void test() {
Model model = ModelFactory.createDefaultModel();
InputStream is = this.getClass().getClassLoader().getResourceAsStream(GRAPH_FILE);
model.read(is, null, "N3");
IOUtils.closeQuietly(is);
GraphCreator creator = new GraphCreator();
ColouredGraph graph = creator.processModel(model);
InDegreeDistributionMetric metric = new InDegreeDistributionMetric();
IntDistribution distribution = metric.apply(graph);
Assert.assertArrayEquals(EXPECTED_DEGREES, distribution.sampleSpace);
for (int i = 0; i < EXPECTED_DEGREE_VALUES.length; ++i) {
Assert.assertEquals(EXPECTED_DEGREE_VALUES[i], distribution.values[i], DELTA);
}
Assert.assertEquals(EXPECTED_DEGREE_VALUES.length, distribution.values.length);
}