本文整理汇总了Java中org.apache.any23.source.DocumentSource类的典型用法代码示例。如果您正苦于以下问题:Java DocumentSource类的具体用法?Java DocumentSource怎么用?Java DocumentSource使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DocumentSource类属于org.apache.any23.source包,在下文中一共展示了DocumentSource类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: _extractTopicsFrom
import org.apache.any23.source.DocumentSource; //导入依赖的package包/类
@Override
public boolean _extractTopicsFrom(URL url, TopicMap topicMap) throws Exception {
if(url != null) {
tripletSource = url.toExternalForm();
Any23 runner = new Any23();
runner.setHTTPUserAgent("Wandora ANY23 Extractor");
HTTPClient httpClient = runner.getHTTPClient();
DocumentSource source = new HTTPDocumentSource(
httpClient,
url.toExternalForm()
);
namespace = url.toExternalForm();
TripleHandler handler = new TopicMapsCreator(topicMap);
runner.extract(source, handler);
}
tripletSource = null;
return true;
}
示例2: run
import org.apache.any23.source.DocumentSource; //导入依赖的package包/类
private static void run(String uri, String outputDir, String outputFormat) throws IOException, URISyntaxException, ExtractionException {
Any23 runner = new Any23();
runner.setHTTPUserAgent("Eurosentiment Crawler");
HTTPClient httpClient = runner.getHTTPClient();
DocumentSource source = new HTTPDocumentSource(
httpClient,
uri
);
ByteArrayOutputStream out = new ByteArrayOutputStream();
TripleHandler handler = null;
if (outputFormat != null) {
switch (outputFormat) {
case "turtle":
handler = new TurtleWriter(out);
break;
case "ntriples":
handler = new NTriplesWriter(out);
break;
case "rdfxml":
handler = new RDFXMLWriter(out);
break;
case "nquads":
handler = new NQuadsWriter(out);
break;
case "trix":
handler = new TriXWriter(out);
break;
case "json":
handler = new JSONWriter(out);
break;
default:
System.out.println("No output writer found for type: " + outputFormat);
System.out.println("Defaulting to Turtle output serialization");
handler = new TurtleWriter(out);
break;
}
System.out.println("Selected " + handler.getClass().getSimpleName() + " as output writer.");
}
try {
runner.extract(source, handler);
} finally {
try {
handler.close();
} catch (TripleHandlerException e) {
e.printStackTrace();
}
}
if (outputDir != null) {
FileUtils.writeStringToFile(new File(outputDir + "/sentiment.txt"), out.toString("UTF-8"));
System.out.println("Successfully wrote file to: " + outputDir + "/sentiment.txt");
} else {
FileUtils.writeStringToFile(new File("sentiment.txt"), out.toString("UTF-8"));
System.out.println("Successfully wrote file to sentiment.txt");
}
}