本文整理汇总了C#中ParseContext.set方法的典型用法代码示例。如果您正苦于以下问题:C# ParseContext.set方法的具体用法?C# ParseContext.set怎么用?C# ParseContext.set使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ParseContext
的用法示例。
在下文中一共展示了ParseContext.set方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Extract
public TextExtractionResult Extract(Func<Metadata, InputStream> streamFactory)
{
try
{
var parser = new AutoDetectParser();
var metadata = new Metadata();
var parseContext = new ParseContext();
//use the base class type for the key or parts of Tika won't find a usable parser
parseContext.set(typeof(Parser), parser);
var content = new System.IO.StringWriter();
var contentHandlerResult = new TextExtractorContentHandler(content);
using (var inputStream = streamFactory(metadata))
{
try
{
parser.parse(inputStream, contentHandlerResult, metadata, parseContext);
}
finally
{
inputStream.close();
}
}
return AssembleExtractionResult(content.ToString(), metadata);
}
catch (Exception ex)
{
throw new TextExtractionException("Extraction failed.", ex);
}
}
示例2: ExtractText
public string ExtractText(byte[] data)
{
var parser = new AutoDetectParser();
var handler = new BodyContentHandler();
var context = new ParseContext();
context.set(parser.getClass(), parser);
var metadata = new Metadata();
using (var output = new StringWriter()) {
var transformerHandler = CreateTransformerHandler(output);
using (var inputStream = TikaInputStream.get(data, metadata)) {
parser.parse(inputStream, transformerHandler, metadata, context);
inputStream.close();
}
return output.toString();
}
}
示例3: Extract
public TextExtractionResult Extract(Func<Metadata, InputStream> streamFactory)
{
try
{
var parser = new AutoDetectParser();
var metadata = new Metadata();
var outputWriter = new StringWriter();
var parseContext = new ParseContext();
//use the base class type for the key or parts of Tika won't find a usable parser
parseContext.set(typeof(org.apache.tika.parser.Parser), parser);
using (var inputStream = streamFactory(metadata))
{
try
{
parser.parse(inputStream, getTransformerHandler(outputWriter), metadata, parseContext);
}
finally
{
inputStream.close();
}
}
return assembleExtractionResult(outputWriter.ToString(), metadata);
}
catch (Exception ex)
{
throw new TextExtractionException("Extraction failed.", ex);
}
}
示例4: Extract
public TextExtractionResult Extract(string filePath)
{
if (!System.IO.File.Exists(filePath))
throw new System.ArgumentException("File does not exist");
var parser = new AutoDetectParser();
var metadata = new Metadata();
var parseContext = new ParseContext();
Class parserClass = parser.GetType();
parseContext.set(parserClass, parser);
try {
var file = new File(filePath);
var url = file.toURI().toURL();
using (var inputStream = TikaInputStream.get(url, metadata)) {
parser.parse(inputStream, getTransformerHandler(), metadata, parseContext);
inputStream.close();
}
return assembleExtractionResult(_outputWriter.toString(), metadata);
} catch (Exception ex) {
throw new ApplicationException(string.Format("Extraction of text from the file '{0}' failed.", filePath), ex);
}
}