本文整理汇总了Java中org.apache.jena.riot.RDFDataMgr.parse方法的典型用法代码示例。如果您正苦于以下问题:Java RDFDataMgr.parse方法的具体用法?Java RDFDataMgr.parse怎么用?Java RDFDataMgr.parse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.jena.riot.RDFDataMgr
的用法示例。
在下文中一共展示了RDFDataMgr.parse方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parse
import org.apache.jena.riot.RDFDataMgr; //导入方法依赖的package包/类
public static PipedRDFIterator<Triple> parse(String dump){
PipedRDFIterator<Triple> iter = new PipedRDFIterator<Triple>();
final String d=dump;
System.out.println(d);
final PipedRDFStream<Triple> inputStream = new PipedTriplesStream(iter);
// PipedRDFStream and PipedRDFIterator need to be on different threads
ExecutorService executor = Executors.newSingleThreadExecutor();
// Create a runnable for our parser thread
Runnable parser = new Runnable() {
@Override
public void run() {
// Call the parsing process.
RDFDataMgr.parse(inputStream, d);
}
};
// Start the parser on another thread
executor.submit(parser);
return iter;
}
示例2: analyze
import org.apache.jena.riot.RDFDataMgr; //导入方法依赖的package包/类
@Override
public Iterator<byte[]> analyze(CrawleableUri curi, File data, Sink sink) {
FileInputStream fin = null;
try {
// First, try to get the language of the data
Lang lang = null;
String contentType = (String) curi.getData(HttpHeaders.CONTENT_TYPE);
if (contentType != null) {
lang = RDFLanguages.contentTypeToLang(contentType);
} else {
lang = RDFLanguages.filenameToLang(data.getName(), null);
}
FilterSinkRDF filtered = new FilterSinkRDF(curi, sink);
RDFDataMgr.parse(filtered, data.getAbsolutePath(), lang);
} catch (Exception e) {
LOGGER.error("Exception while analyzing. Aborting.");
} finally {
IOUtils.closeQuietly(fin);
}
return collector.getUris(curi);
}
示例3: parseTriples
import org.apache.jena.riot.RDFDataMgr; //导入方法依赖的package包/类
/**
* Uses RDFDataMgr to parse triples by constructing the CollectorStreamTriples as the input stream
*/
@SuppressWarnings("unchecked")
private void parseTriples() {
Assert.state(fileName.length() != 0, "FileName must not be null.");
try {
inputStream = new CollectorStreamTriples();
Assert.state(inputStream != null, "inputStream must not be null");
RDFDataMgr.parse(inputStream, fileName);
logger.info("Number of Triples [" + inputStream.getCollected().size() + "]");
tripleIterator = (Iterator<T>) inputStream.getCollected().iterator();
Assert.state(tripleIterator != null, "tripleIterator must not be null. Something went wrong");
}
catch (Exception e) {
close();
logger.info("Caught exception[" + e.getMessage() + "]");
}
}
示例4: test00GetVoidInformation
import org.apache.jena.riot.RDFDataMgr; //导入方法依赖的package包/类
/**
* Test method for VoidParsingExtractor#getVoidInformation()
* 0.nt
*/
@Test
public final void test00GetVoidInformation() {
// set input file
String inFile = "src/test/data/0.nt";
// run extraction
try {
// setup
InputStream inStream = new FileInputStream( inFile );
PipedRDFIterator<Triple> iter = new PipedRDFIterator<Triple>();
PipedRDFStream<Triple> rdfStream = new PipedTriplesStream( iter );
// run
RDFDataMgr.parse(rdfStream, inStream, "", RDFLanguages.resourceNameToLang( inFile ) );
VoidParsingExtractor extractor = new VoidParsingExtractor();
extractor.extract( iter );
// print
System.out.println( "0.nt\n " + extractor.getVoidInformation().toString() );
// test
assertEquals( 0, extractor.getVoidInformation().size() );
}
catch( Exception e ) {
fail( e.toString() );
}
}
示例5: test051GetVoidInformation
import org.apache.jena.riot.RDFDataMgr; //导入方法依赖的package包/类
/**
* Test method for VoidParsingExtractor#getVoidInformation()
* 5.nt
*/
@Test
public final void test051GetVoidInformation() {
// set input file
String inFile = "src/test/data/5.nt";
// run extraction
try {
// setup
InputStream inStream = new FileInputStream( inFile );
PipedRDFIterator<Triple> iter = new PipedRDFIterator<Triple>();
PipedRDFStream<Triple> rdfStream = new PipedTriplesStream( iter );
// run
RDFDataMgr.parse(rdfStream, inStream, "", RDFLanguages.resourceNameToLang( inFile ) );
VoidParsingExtractor extractor = new VoidParsingExtractor();
extractor.extract( iter );
// print
System.out.println( "5.nt:\n " + extractor.getVoidInformation().toString() );
// test
assertEquals( 0, extractor.getVoidInformation().size() );
}
catch( Exception e ) {
fail( e.toString() );
}
}
示例6: test052GetVoidInformation
import org.apache.jena.riot.RDFDataMgr; //导入方法依赖的package包/类
/**
* Test method for VoidParsingExtractor#getVoidInformation()
* expected_5.nt
*/
@Test
public final void test052GetVoidInformation() {
// set input file
String inFile = "src/test/data/expected_5.nt";
// run extraction
try {
// setup
InputStream inStream = new FileInputStream( inFile );
PipedRDFIterator<Triple> iter = new PipedRDFIterator<Triple>();
PipedRDFStream<Triple> rdfStream = new PipedTriplesStream( iter );
// run
RDFDataMgr.parse(rdfStream, inStream, "", RDFLanguages.resourceNameToLang( inFile ) );
VoidParsingExtractor extractor = new VoidParsingExtractor();
extractor.extract( iter );
// print
System.out.println( "expected_5.nt:\n " + extractor.getVoidInformation().toString() );
// test
assertEquals( 11, extractor.getVoidInformation().size() );
}
catch( Exception e ) {
fail( e.toString() );
}
}
示例7: parseStream
import org.apache.jena.riot.RDFDataMgr; //导入方法依赖的package包/类
private Model parseStream(final InputStream in) throws IOException {
final SubjectMappingStreamRDF mapper = new SubjectMappingStreamRDF(config.getSource(),
config.getDestination());
try (final InputStream in2 = in) {
RDFDataMgr.parse(mapper, in2, contentTypeToLang(config.getRdfLanguage()));
}
return mapper.getModel();
}
示例8: toPatch
import org.apache.jena.riot.RDFDataMgr; //导入方法依赖的package包/类
protected RDFPatch toPatch(String fn) {
// .gz??
Lang lang = RDFLanguages.filenameToLang(fn);
if ( lang != null && ( RDFLanguages.isTriples(lang) || RDFLanguages.isQuads(lang) ) ) {
RDFChangesCollector x = new RDFChangesCollector();
StreamRDF dest = new RDF2Patch(x);
// dest will do the start-finish on the RDFChangesCollector via parsing.
RDFDataMgr.parse(dest, fn);
return x.getRDFPatch();
}
// Not RDF - assume a text patch.
// String ext = FileOps.extension(fn);
// switch(ext) {
// case RDFPatchConst.EXT:
// break;
// case RDFPatchConst.EXT_B:
// break;
// default:
// Log.warn(addpatch.class, "Conventionally, patches have file extension ."+RDFPatchConst.EXT);
// }
Path path = Paths.get(fn);
try(InputStream in = Files.newInputStream(path) ) {
return RDFPatchOps.read(in);
} catch (IOException ex ) { throw IOX.exception(ex); }
}
示例9: rdf2patch
import org.apache.jena.riot.RDFDataMgr; //导入方法依赖的package包/类
/** RDF data file to patch.
* The patch has no Id or Previous - see {@link #withHeader}.
*/
public static RDFPatch rdf2patch(String rdfDataFile) {
RDFChangesCollector x = new RDFChangesCollector();
RDF2Patch dest = new RDF2Patch(x);
dest.start();
RDFDataMgr.parse(dest, rdfDataFile);
dest.finish();
// Headers.
RDFPatch patch = x.getRDFPatch();
return patch;
}
示例10: datasource_init_01
import org.apache.jena.riot.RDFDataMgr; //导入方法依赖的package包/类
@Test
public void datasource_init_01() {
DeltaLink dLink = getLinkRegistered();
Id dsRef = dLink.newDataSource("datasource_15", "http://example/uri");
assertEquals(1, dLink.listDatasets().size());
DataSourceDescription dsd = dLink.getDataSourceDescriptionByURI("http://example/uri-not-present");
String url = dLink.initialState(dsRef);
assertNotNull(url);
RDFDataMgr.parse(StreamRDFLib.sinkNull(), url);
}
示例11: match
import org.apache.jena.riot.RDFDataMgr; //导入方法依赖的package包/类
public static boolean match(String turtle, Node subject, Node predicate, Node object) {
MatchSinkRDF matcher = new MatchSinkRDF(subject, predicate, object);
RDFDataMgr.parse(matcher,
new StringReader(turtle), Lang.TURTLE);
return matcher.match;
}
示例12: load
import org.apache.jena.riot.RDFDataMgr; //导入方法依赖的package包/类
private AQuiXEvent load(final RDFStreamSource source) {
// Create a PipedRDFStream to accept input and a PipedRDFIterator to
// consume it
// You can optionally supply a buffer size here for the
// PipedRDFIterator, see the documentation for details about recommended
// buffer sizes
// this.iter = new PipedRDFIterator<Tuple<Node>>();
this.iter = new PipedRDFIterator<Triple>();
// final PipedRDFStream<Tuple<Node>> tripleStream = new
// PipedTuplesStream(this.iter);
final StreamRDF tripleStream = new PipedTriplesStream(this.iter);
final TypedInputStream tis = source.asTypedInputStream();
// PipedRDFStream and PipedRDFIterator need to be on different threads
this.executor = Executors.newSingleThreadExecutor();
// Create a runnable for our parser thread
final Runnable parser = () -> {
// Call the parsing process.
// System.out.println("started thread before");
RDFDataMgr.parse(tripleStream, tis, Lang.N3);
// System.out.println("started thread after");
};
// Start the parser on another thread
this.executor.execute(parser);
return AQuiXEvent.getStartRDF();
}
示例13: test00GetCountedClasses
import org.apache.jena.riot.RDFDataMgr; //导入方法依赖的package包/类
/**
* Test method for VoidExtractor#getCountedClasses().
* 0.nt
*/
@Test
public final void test00GetCountedClasses() {
// set input file
String inFile = "src/test/data/0.nt";
// set expected result
ObjectIntOpenHashMap<String> expected = new ObjectIntOpenHashMap<String>();
expected.putOrAdd( "http://example.org/Class1", 1, 1 );
expected.putOrAdd( "http://example.org/Class2", 0, 0 );
expected.putOrAdd( "http://www.w3.org/2000/01/rdf-schema#Class", 1, 1 );
// run extraction
try {
// setup
InputStream inStream = new FileInputStream( inFile );
PipedRDFIterator<Triple> iter = new PipedRDFIterator<Triple>();
PipedRDFStream<Triple> rdfStream = new PipedTriplesStream( iter );
// run
RDFDataMgr.parse(rdfStream, inStream, "", RDFLanguages.resourceNameToLang( inFile ) );
VoidExtractor extractor = new VoidExtractor();
extractor.extract( iter );
// print
System.out.println( "0.nt:\n CLASSES: " + extractor.getCountedClasses().toString() );
// test
assertEquals( expected, extractor.getCountedClasses() );
}
catch( Exception e ) {
fail( e.toString() );
}
}
示例14: test05GetCountedClasses
import org.apache.jena.riot.RDFDataMgr; //导入方法依赖的package包/类
/**
* Test method for VoidExtractor#getCountedClasses().
* 5.nt
*/
@Test
public final void test05GetCountedClasses() {
// set input file
String inFile = "src/test/data/5.nt";
// set expected result
ObjectIntOpenHashMap<String> expected = new ObjectIntOpenHashMap<String>();
expected.putOrAdd( "http://example.org/class2", 0, 0 );
expected.putOrAdd( "http://www.w3.org/1999/02/22-rdf-syntax-ns#Property", 2, 2 );
expected.putOrAdd( "http://example.org/class1", 0, 0 );
expected.putOrAdd( "http://www.w3.org/2000/01/rdf-schema#Class", 2, 2 );
// run extraction
try {
// setup
InputStream inStream = new FileInputStream( inFile );
PipedRDFIterator<Triple> iter = new PipedRDFIterator<Triple>();
PipedRDFStream<Triple> rdfStream = new PipedTriplesStream( iter );
// run
RDFDataMgr.parse(rdfStream, inStream, "", RDFLanguages.resourceNameToLang( inFile ) );
VoidExtractor extractor = new VoidExtractor();
extractor.extract( iter );
// print
System.out.println( "5.nt:\n CLASSES: " + extractor.getCountedClasses().toString() );
// test
assertEquals( expected, extractor.getCountedClasses() );
}
catch( Exception e ) {
fail( e.toString() );
}
}
示例15: test10GetCountedProperties
import org.apache.jena.riot.RDFDataMgr; //导入方法依赖的package包/类
/**
* Test method for VoidExtractor#getCountedProperties().
* 0.nt
*/
@Test
public final void test10GetCountedProperties() {
// set input file
String inFile = "src/test/data/0.nt";
// set expected result
ObjectIntOpenHashMap<String> expected = new ObjectIntOpenHashMap<String>();
expected.putOrAdd( "http://www.w3.org/1999/02/22-rdf-syntax-ns#type", 2, 2 );
expected.putOrAdd( "http://www.w3.org/2000/01/rdf-schema#label", 1, 1 );
// run extraction
try {
// setup
InputStream inStream = new FileInputStream( inFile );
PipedRDFIterator<Triple> iter = new PipedRDFIterator<Triple>();
PipedRDFStream<Triple> rdfStream = new PipedTriplesStream( iter );
// run
RDFDataMgr.parse(rdfStream, inStream, "", RDFLanguages.resourceNameToLang( inFile ) );
VoidExtractor extractor = new VoidExtractor();
extractor.extract( iter );
// print
System.out.println( "0.nt:\n PROPERTIES: " + extractor.getCountedProperties().toString() );
// test
assertEquals( expected, extractor.getCountedProperties() );
}
catch( Exception e ) {
fail( e.toString() );
}
}