本文整理匯總了Java中org.openrdf.rio.Rio.parse方法的典型用法代碼示例。如果您正苦於以下問題:Java Rio.parse方法的具體用法?Java Rio.parse怎麽用?Java Rio.parse使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.openrdf.rio.Rio
的用法示例。
在下文中一共展示了Rio.parse方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getResource
import org.openrdf.rio.Rio; //導入方法依賴的package包/類
private Model getResource(UriBuilder uriBuilder) {
RDFFormat format = RDFFormat.TURTLE;
try {
java.net.URI target = credentials.buildUrl(uriBuilder);
log.debug("Exporting {} data from resource {}", format.getName(), target.toString());
String entity = client.get(target, format.getDefaultMIMEType());
return Rio.parse(new StringReader(entity), target.toString(), format, new ParserConfig(), ValueFactoryImpl.getInstance(), new ParseErrorLogger());
} catch (IllegalArgumentException | URISyntaxException | RDFParseException | IOException e) {
if (e instanceof ClientProtocolException && "Unexpected response status: 404".compareTo(e.getMessage())==0) {
//keeping old behavior, should not be silently fail (i.e. return empty model)?
return new LinkedHashModel();
} else {
throw new RuntimeException(e);
}
}
}
示例2: testImportCheckDataHub
import org.openrdf.rio.Rio; //導入方法依賴的package包/類
@Test
public void testImportCheckDataHub() throws IOException, RDFParseException, RDFHandlerException, URISyntaxException {
InputStream in = this.getClass().getResourceAsStream(TEST_FILE);
Assume.assumeNotNull(in);
String base = buildDatasetBaseUri(credentials, status.getOwner(), TEST_DATASET);
final Model model = Rio.parse(in, base, TEST_FILE_FORMAT);
Assert.assertTrue(redlink.importDataset(model, TEST_DATASET));
RestAssured
.given()
.header("Accept", "text/turtle")
.expect()
.statusCode(200)
.contentType("text/turtle")
.get(base + TEST_RESOURCE);
}
示例3: testResourceImported
import org.openrdf.rio.Rio; //導入方法依賴的package包/類
@Test
public void testResourceImported() throws IOException, RDFParseException, RDFHandlerException, URISyntaxException {
//first import data
InputStream in = this.getClass().getResourceAsStream(TEST_FILE);
Assume.assumeNotNull(in);
final Model model = Rio.parse(in, buildDatasetBaseUri(credentials, status.getOwner(), TEST_DATASET), TEST_FILE_FORMAT);
Assert.assertTrue(redlink.importDataset(model, TEST_DATASET, true));
final SPARQLResult triples = redlink.sparqlTupleQuery(QUERY_SELECT, TEST_DATASET);
Assert.assertNotNull(triples);
Assert.assertEquals(TEST_FILE_TRIPLES, triples.size());
//and then the actual test
String resource = buildDatasetBaseUri(credentials, status.getOwner(), TEST_DATASET) + TEST_RESOURCE;
Model resourceModel = redlink.getResource(resource, TEST_DATASET);
Assert.assertNotNull(resourceModel);
Assert.assertTrue(resourceModel.size() < triples.size());
Assert.assertEquals(TEST_RESOUCE_TRIPLES, resourceModel.size());
}
示例4: testResourceReImported
import org.openrdf.rio.Rio; //導入方法依賴的package包/類
@Test
@Ignore
public void testResourceReImported() throws IOException, RDFParseException, RDFHandlerException, URISyntaxException {
//first import data
InputStream in = this.getClass().getResourceAsStream(TEST_FILE);
Assume.assumeNotNull(in);
final Model model = Rio.parse(in, buildDatasetBaseUri(credentials, status.getOwner(), TEST_DATASET), TEST_FILE_FORMAT);
Assert.assertTrue(redlink.importDataset(model, TEST_DATASET, true));
final SPARQLResult triples = redlink.sparqlTupleQuery(QUERY_SELECT, TEST_DATASET);
Assert.assertNotNull(triples);
Assert.assertEquals(TEST_FILE_TRIPLES, triples.size());
//and then the actual test
final String resource = buildDatasetBaseUri(credentials, status.getOwner(), TEST_DATASET) + TEST_RESOURCE;
final ValueFactoryImpl vf = new ValueFactoryImpl();
final Resource sesameResource = vf.createURI(resource);
final Model resourceModel = new LinkedHashModel();
resourceModel.add(sesameResource, vf.createURI("http://example.org/foo"), vf.createLiteral("foo"));
Assert.assertTrue(redlink.importResource(resource, model, TEST_DATASET, true));
final Model resourceModelFromApi = redlink.getResource(resource, TEST_DATASET);
Assert.assertNotNull(resourceModelFromApi);
Assert.assertEquals(resourceModel.size(), resourceModelFromApi.size());
}
示例5: testDatasetCleanImportDescribe
import org.openrdf.rio.Rio; //導入方法依賴的package包/類
@Test
public void testDatasetCleanImportDescribe() throws IOException, RDFParseException, RDFHandlerException, URISyntaxException {
Assume.assumeTrue(redlink.sparqlUpdate(QUERY_CLEAN, TEST_DATASET));
Assert.assertEquals(0, getCurrentSize(TEST_DATASET));
InputStream in = this.getClass().getResourceAsStream(TEST_FILE);
Assume.assumeNotNull(in);
String dataset = buildDatasetBaseUri(credentials, status.getOwner(), TEST_DATASET);
final Model model = Rio.parse(in, dataset, TEST_FILE_FORMAT);
Assert.assertTrue(redlink.importDataset(model, TEST_DATASET));
String resource = dataset + TEST_RESOURCE;
final Model result = redlink.sparqlGraphQuery("DESCRIBE <" + resource + ">", TEST_DATASET);
Assert.assertNotNull(result);
Assert.assertFalse(result.isEmpty());
Assert.assertEquals(8, result.size());
}
示例6: VocabBuilder
import org.openrdf.rio.Rio; //導入方法依賴的package包/類
public VocabBuilder(String filename, RDFFormat format) throws IOException, RDFParseException {
Path file = Paths.get(filename);
if (!Files.exists(file)) throw new FileNotFoundException(filename);
if (format == null) {
format = Rio.getParserFormatForFileName(filename);
log.trace("detected input format from filename {}: {}", filename, format);
}
try (final InputStream inputStream = Files.newInputStream(file)) {
log.trace("Loading input file");
model = Rio.parse(inputStream, "", format);
}
//import
Set<Resource> owlOntologies = model.filter(null, RDF.TYPE, OWL.ONTOLOGY).subjects();
if (!owlOntologies.isEmpty()) {
setPrefix(owlOntologies.iterator().next().stringValue());
}
}
示例7: getSparqlUpdate
import org.openrdf.rio.Rio; //導入方法依賴的package包/類
private static String getSparqlUpdate() throws Exception {
InputStream stream = Thread.currentThread().getContextClassLoader().getResourceAsStream("namedgraphs.trig");
assertNotNull(stream);
Model m = Rio.parse(stream, "", RDFFormat.TRIG);
StringBuffer updateStr = new StringBuffer();
updateStr.append("INSERT DATA {\n");
for (Statement s : m){
if (s.getContext() != null) {
updateStr.append("graph ");
updateStr.append(escape(s.getContext()));
updateStr.append("{ ");
}
updateStr.append(escape(s.getSubject()));
updateStr.append(" ");
updateStr.append(escape(s.getPredicate()));
updateStr.append(" ");
updateStr.append(escape(s.getObject()));
if (s.getContext() != null){
updateStr.append("}");
}
updateStr.append(" . \n");
}
updateStr.append("}");
return updateStr.toString();
}
示例8: exportDataset
import org.openrdf.rio.Rio; //導入方法依賴的package包/類
@Override
public Model exportDataset(String dataset) {
RDFFormat format = RDFFormat.TURTLE;
try {
final java.net.URI target = credentials.buildUrl(getDatasetUriBuilder(dataset));
log.debug("Exporting {} data from dataset {}", format.getName(), dataset);
final String entity = client.get(target, format.getDefaultMIMEType());
return Rio.parse(new StringReader(entity), target.toString(), format, new ParserConfig(), ValueFactoryImpl.getInstance(), new ParseErrorLogger());
} catch (IllegalArgumentException | URISyntaxException | RDFParseException | IOException e) {
throw new RuntimeException(e);
}
}
示例9: testImport
import org.openrdf.rio.Rio; //導入方法依賴的package包/類
@Test
public void testImport() throws IOException, RDFParseException, RDFHandlerException, URISyntaxException {
InputStream in = this.getClass().getResourceAsStream(TEST_FILE);
Assume.assumeNotNull(in);
String base = buildDatasetBaseUri(credentials, status.getOwner(), TEST_DATASET);
final Model model = Rio.parse(in, base, TEST_FILE_FORMAT);
Assert.assertTrue(redlink.importDataset(model, TEST_DATASET));
final SPARQLResult triples = redlink.sparqlTupleQuery(QUERY_SELECT, TEST_DATASET);
Assert.assertNotNull(triples);
Assert.assertTrue(triples.size() >= TEST_FILE_TRIPLES);
//TODO: more specific testing
}
示例10: testLDPath
import org.openrdf.rio.Rio; //導入方法依賴的package包/類
@Test
public void testLDPath() throws IOException, RDFParseException, RDFHandlerException, URISyntaxException {
InputStream in = this.getClass().getResourceAsStream(TEST_FILE);
Assume.assumeNotNull(in);
final Model model = Rio.parse(in, buildDatasetBaseUri(credentials, status.getOwner(), TEST_DATASET), TEST_FILE_FORMAT);
Assert.assertTrue(redlink.importDataset(model, TEST_DATASET, true));
String resource = buildDatasetBaseUri(credentials, status.getOwner(), TEST_DATASET) + TEST_RESOURCE;
final LDPathResult results = redlink.ldpath(resource, TEST_DATASET, "name = foaf:name[@en] :: xsd:string ;");
Assert.assertNotNull(results);
Assert.assertTrue(results.size() > 0);
Assert.assertTrue(results.getFields().contains("name"));
Assert.assertTrue(results.getResults("name").size() > 0);
Assert.assertEquals("John Pereira", results.getResults("name").get(0).toString());
}
示例11: testLDPathNoDataset
import org.openrdf.rio.Rio; //導入方法依賴的package包/類
@Test
public void testLDPathNoDataset() throws IOException, RDFParseException, RDFHandlerException, URISyntaxException {
InputStream in = this.getClass().getResourceAsStream(TEST_FILE);
Assume.assumeNotNull(in);
final Model model = Rio.parse(in, buildDatasetBaseUri(credentials, status.getOwner(), TEST_DATASET), TEST_FILE_FORMAT);
Assert.assertTrue(redlink.importDataset(model, TEST_DATASET, true));
String resource = buildDatasetBaseUri(credentials, status.getOwner(), TEST_DATASET) + TEST_RESOURCE;
final LDPathResult results = redlink.ldpath(resource, "name = foaf:name[@en] :: xsd:string ;");
Assert.assertNotNull(results);
Assert.assertTrue(results.size() > 0);
Assert.assertTrue(results.getFields().contains("name"));
Assert.assertTrue(results.getResults("name").size() > 0);
Assert.assertEquals("John Pereira", results.getResults("name").get(0).toString());
}
示例12: parseStatements
import org.openrdf.rio.Rio; //導入方法依賴的package包/類
private Model parseStatements(File file) throws IOException, RDFParseException {
FileInputStream inputStream = new FileInputStream(file);
RDFFormat rdfFormat = Rio.getParserFormatForFileName(file.getName());
Model model = Rio.parse(inputStream, file.toURI().toString(), rdfFormat);
inputStream.close();
return model;
}
示例13: testTranslateStatements
import org.openrdf.rio.Rio; //導入方法依賴的package包/類
public void testTranslateStatements() throws Exception {
TranslationApi translatorApi = new BingTranslator();
translatorApi.setClientId("CLIENTID");
translatorApi.setClientSecret("CLIENTSECRET");
Model statements = Rio.parse(this.getClass().getResourceAsStream("statements.ttl"), "", RDFFormat.TURTLE);
translatorApi.translateStatements(statements);
}
示例14: main
import org.openrdf.rio.Rio; //導入方法依賴的package包/類
public static void main(String[] args) throws RDFParseException, UnsupportedRDFormatException, IOException,
RepositoryException, ReferringExpressionException, RDFHandlerException {
Options options = new Options();
new JCommander(options, args);
FileInputStream in = new FileInputStream(options.rdf);
Model m = Rio.parse(in, "http://localhost/", RDFFormat.NTRIPLES);
ReferringExpressionAlgorithm algorithm = null;
if (options.algorithm.equals(DaleReiterAlgorithm.class.getName())) {
algorithm = new DaleReiterAlgorithm(TypePriorities.dbPediaPriorities, TypePriorities.dbPediaIgnored);
if (options.verbose)
((ch.qos.logback.classic.Logger) DaleReiterAlgorithm.logger).setLevel(Level.DEBUG);
} else if (options.algorithm.equals(GardentAlgorithm.class.getName())) {
algorithm = new GardentAlgorithm(TypePriorities.dbPediaPriorities, TypePriorities.dbPediaIgnored);
if (options.verbose)
((ch.qos.logback.classic.Logger) GardentAlgorithm.logger).setLevel(Level.DEBUG);
} else if (options.algorithm.equals(GraphAlgorithm.class.getName())) {
algorithm = new GraphAlgorithm(TypePriorities.dbPediaPriorities, TypePriorities.dbPediaIgnored);
if (options.verbose)
((ch.qos.logback.classic.Logger) GraphAlgorithm.logger).setLevel(Level.DEBUG);
} else {
System.err.println("Unknown algorithm '" + options.algorithm + "'");
System.exit(-1);
}
Repository rep = new SailRepository(new MemoryStore());
rep.initialize();
ValueFactory f = rep.getValueFactory();
List<URI> confusors = new ArrayList<URI>(options.confusors.size());
for (String confusor : options.confusors)
confusors.add(f.createURI(confusor));
RepositoryConnection conn = rep.getConnection();
try {
conn.add(m);
URI referent = f.createURI(options.referent);
if (options.type != null)
conn.add(referent, RDF.TYPE, f.createURI(options.type));
ReferringExpression r = algorithm.resolve(referent, confusors, conn);
System.out.println(r);
} finally {
conn.close();
}
}