本文整理汇总了Java中com.hp.hpl.jena.rdf.model.RDFReader.read方法的典型用法代码示例。如果您正苦于以下问题:Java RDFReader.read方法的具体用法?Java RDFReader.read怎么用?Java RDFReader.read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.hp.hpl.jena.rdf.model.RDFReader
的用法示例。
在下文中一共展示了RDFReader.read方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: load
import com.hp.hpl.jena.rdf.model.RDFReader; //导入方法依赖的package包/类
public ModuleHelper load(final URI base,final Format format) throws IOException {
final String data=
new String(
Files.readAllBytes(this.file),
StandardCharsets.UTF_8);
if(!format.equals(Format.RDF_XML) || RDFXMLUtil.isStandaloneDocument(data)) {
try {
this.model =ModelFactory.createDefaultModel();
this.format=format;
final RDFReader reader = this.model.getReader(format.lang.getLabel());
reader.setProperty("error-mode", "strict-fatal");
reader.read(this.model,new StringReader(data),base.toString());
} catch (final RiotException e) {
this.model=null;
this.format=format;
throw new IOException("Parsing failed",e);
}
}
return this;
}
示例2: readRDFMetaDataFile
import com.hp.hpl.jena.rdf.model.RDFReader; //导入方法依赖的package包/类
public static Model readRDFMetaDataFile(File rdfMetaDataFile){
RDFReader reader = new TurtleReader();
Model rdfMetaDataModel = ModelFactory.createDefaultModel();
LOGGER.info("Loading meta data file from " + rdfMetaDataFile.getAbsolutePath());
FileInputStream fin = null;
try {
fin = new FileInputStream(rdfMetaDataFile);
reader.read(rdfMetaDataModel, fin, "");
} catch (FileNotFoundException e) {
LOGGER.error("Couldn't read meta data from file. Returning null.", e);
return null;
} finally {
IOUtils.closeQuietly(fin);
}
return rdfMetaDataModel;
}
示例3: handleEvent
import com.hp.hpl.jena.rdf.model.RDFReader; //导入方法依赖的package包/类
public void handleEvent(String eventString) {
buildGraph();
RDFReaderF readerFactory = new RDFReaderFImpl();
RDFReader reader = readerFactory.getReader("N3");
Model model = ModelFactory.createModelForGraph(eventGraph);
reader.read(
model,
new StringReader(eventString),
DEFAULT_BASE);
logger.debug("Launching update thread... ");
// LocalTimer.get().schedule(
// new TimerTask() {
// // public void run() {
RunnableContextFactory.getDefaultRunnableContext().run(
new Runnable() {
public void run() {
logger.debug("Sending update events ... ");
eventGraph.sendUpdateEvents();
logger.debug("Update events sent!");
}
} );
// }
// }, 0 );
// logger.debug("Update thread launched!");
}
示例4: load
import com.hp.hpl.jena.rdf.model.RDFReader; //导入方法依赖的package包/类
public static Model load(final Context context, final String relativePath) throws IOException {
final Path file=moduleLocation(context,relativePath);
final Model model=ModelFactory.createDefaultModel();
final RDFReader reader=model.getReader("TURTLE");
reader.setProperty("error-mode", "strict-fatal");
reader.
read(
model,
new FileReader(
file.toFile()),
context.getCanonicalNamespace(file).toString());
return model;
}
示例5: readModel
import com.hp.hpl.jena.rdf.model.RDFReader; //导入方法依赖的package包/类
protected Model readModel(String metaDataModelFile) {
RDFReader reader = new TurtleReader();
Model model = ModelFactory.createDefaultModel();
FileInputStream fin = null;
try {
fin = new FileInputStream(metaDataModelFile);
reader.read(model, fin, LOD_STATS_DOC_BASE_URI);
} catch (FileNotFoundException e) {
LOGGER.error("Couldn't read model with additional meta data from file. Ignoring this file.", e);
return null;
} finally {
IOUtils.closeQuietly(fin);
}
return model;
}
示例6: readClassHierarchy
import com.hp.hpl.jena.rdf.model.RDFReader; //导入方法依赖的package包/类
protected void readClassHierarchy(File file, String rdfLang, String baseUri, Model model) throws IOException {
InputStream is = null;
RDFReader rdfReader = factory.getReader(rdfLang);
try {
is = new BufferedInputStream(new FileInputStream(file));
rdfReader.read(model, is, baseUri);
} finally {
IOUtils.closeQuietly(is);
}
}
示例7: getModelFromTurtleFile
import com.hp.hpl.jena.rdf.model.RDFReader; //导入方法依赖的package包/类
private Model getModelFromTurtleFile(String path){
InputStream input = getClass().getResourceAsStream(path);
Model model = ModelFactory.createDefaultModel();
final RDFReader reader = model.getReader("TTL");
reader.read(model, input, null);
return model;
}
示例8: getModel
import com.hp.hpl.jena.rdf.model.RDFReader; //导入方法依赖的package包/类
public static Model getModel(String file) {
InputStream in;
Model model = ModelFactory.createDefaultModel();
VectorDescription d = new VectorDescription(file);
RDFReader r = model.getReader("TURTLE");
try {
in = new FileInputStream(file);
InputStreamReader reader = new InputStreamReader(in, "UTF8");
r.read(model, reader, null);
logger.info("RDF model read from " + file + " is of size " + model.size());
} catch (Exception e) {
logger.warn("Error reading model " + file);
}
return model;
}
示例9: createEngine
import com.hp.hpl.jena.rdf.model.RDFReader; //导入方法依赖的package包/类
public static TMEngine createEngine(WorkerBasedLabelRetrievingDocumentSupplierDecorator cachingLabelRetriever,
File inputFolder, File metaDataFile) {
LOGGER.info("Loading model from \"" + inputFolder.getAbsolutePath() + "\".");
// read probabilistic word topic Model from file
GZipProbTopicModelingAlgorithmStateReader modelReader = new GZipProbTopicModelingAlgorithmStateReader();
ProbTopicModelingAlgorithmStateSupplier model = (ProbTopicModelingAlgorithmStateSupplier) modelReader
.readProbTopicModelState(new File(inputFolder.getAbsolutePath() + File.separator + MODEL_FILE_NAME));
if (model == null) {
LOGGER.error("Couldn't read model. Returning null.");
return null;
}
ProbabilisticWordTopicModel probModel = (ProbabilisticWordTopicModel) ((ModelingAlgorithm) model).getModel();
GZipCorpusObjectReader corpusReader = new GZipCorpusObjectReader(new File(inputFolder.getAbsolutePath()
+ File.separator + CORPUS_FILE_NAME));
Corpus corpus = corpusReader.getCorpus();
if (corpus == null) {
LOGGER.error("Couldn't read corpus. Returning null.");
return null;
}
ObjectObjectOpenHashMap<String, SimpleVector> knownDatasets = new ObjectObjectOpenHashMap<String, SimpleVector>(
corpus.getNumberOfDocuments());
// translate word topic assignment into topic vectors for each document
SingleDocumentPreprocessor tempPreProc = new SingleDocumentPreprocessor();
DocumentWordCountingSupplierDecorator decorator = new DocumentWordCountingSupplierDecorator(tempPreProc);
tempPreProc.setDocumentSupplier(decorator);
for (int i = 0; i < corpus.getNumberOfDocuments(); ++i) {
// knownDatasets.put(createDataset(corpus.getDocument(i)),
// createVector(model.getWordTopicAssignmentForDocument(i),
// model.getNumberOfTopics()));
// let's use smoothing for this
knownDatasets.put(getUri(corpus.getDocument(i)), new SimpleVector((double[]) probModel
.getClassificationForDocument(tempPreProc.processDocument(corpus.getDocument(i))).getValue()));
}
SingleDocumentPreprocessor preprocessor = createPreprocessing(cachingLabelRetriever, model.getVocabulary());
if (preprocessor == null) {
LOGGER.error("Couldn't create preprocessor. Returning null.");
return null;
}
// Read additional meta data
RDFReader reader = new TurtleReader();
Model metaDataModel = ModelFactory.createDefaultModel();
FileInputStream fin = null;
try {
fin = new FileInputStream(metaDataFile);
reader.read(metaDataModel, fin, "");
} catch (FileNotFoundException e) {
LOGGER.error("Couldn't read meta data from file. Returning null.", e);
return null;
} finally {
IOUtils.closeQuietly(fin);
}
return new TMEngine(probModel, knownDatasets, preprocessor, metaDataModel);
}
示例10: createEngine
import com.hp.hpl.jena.rdf.model.RDFReader; //导入方法依赖的package包/类
public static BLEngine createEngine(File inputFolder, File metaDataFile) {
GZipCorpusObjectReader corpusReader = new GZipCorpusObjectReader(new File(inputFolder.getAbsolutePath()
+ File.separator + CORPUS_FILE_NAME));
Corpus corpus = corpusReader.getCorpus();
if (corpus == null) {
LOGGER.error("Couldn't read corpus. Returning null.");
return null;
}
ObjectObjectOpenHashMap<String, ObjectOpenHashSet<String>> knownDatasets = new ObjectObjectOpenHashMap<String, ObjectOpenHashSet<String>>(
corpus.getNumberOfDocuments());
// generate a URI set for each document
DatasetURIs uris;
for (Document document : corpus) {
uris = document.getProperty(DatasetURIs.class);
if (uris == null) {
LOGGER.warn("Got a document without DatasetURIs property. Ignoring this document.");
} else {
knownDatasets.put(getUri(document), uris.get());
}
}
SingleDocumentPreprocessor preprocessor = createPreprocessing();
if (preprocessor == null) {
LOGGER.error("Couldn't create preprocessor. Returning null.");
return null;
}
// Read additional meta data
RDFReader reader = new TurtleReader();
Model metaDataModel = ModelFactory.createDefaultModel();
FileInputStream fin = null;
try {
fin = new FileInputStream(metaDataFile);
reader.read(metaDataModel, fin, "");
} catch (FileNotFoundException e) {
LOGGER.error("Couldn't read meta data from file. Returning null.", e);
return null;
} finally {
IOUtils.closeQuietly(fin);
}
return new BLEngine(knownDatasets, preprocessor, metaDataModel);
}
示例11: getEntities
import com.hp.hpl.jena.rdf.model.RDFReader; //导入方法依赖的package包/类
@Override
public List<Entity> getEntities(String text) {
List<Entity> list = new ArrayList<>();
try {
String foxJSONOutput = doTASK(text);
JSONParser parser = new JSONParser();
JSONArray jsonArray = (JSONArray) parser.parse(foxJSONOutput);
String output = URLDecoder.decode((String) ((JSONObject) jsonArray.get(0)).get("output"), "UTF-8");
String baseURI = "http://dbpedia.org";
Model model = ModelFactory.createDefaultModel();
RDFReader r = model.getReader("N3");
r.read(model, new StringReader(output), baseURI);
ResIterator iter = model.listSubjects();
while (iter.hasNext()) {
Resource next = iter.next();
StmtIterator statementIter = next.listProperties();
Entity ent = new Entity();
while (statementIter.hasNext()) {
Statement statement = statementIter.next();
String predicateURI = statement.getPredicate().getURI();
if (predicateURI.equals("http://www.w3.org/2000/10/annotation-ns#body")) {
ent.label = statement.getObject().asLiteral().getString();
} else if (predicateURI.equals("http://ns.aksw.org/scms/means")) {
String uri = statement.getObject().asResource().getURI();
String encode = uri.replaceAll(",", "%2C");
ent.URI = encode;
} else if (predicateURI.equals("http://ns.aksw.org/scms/beginIndex")) {
ent.start = statement.getObject().asLiteral().getInt();
} else if (predicateURI.equals("http://ns.aksw.org/scms/endIndex")) {
ent.end = statement.getObject().asLiteral().getInt();
}
}
list.add(ent);
}
} catch (IOException | ParseException e) {
log.error("Could not call FOX for NER/NED", e);
}
return list;
}