Я хочу выделить несколько ключевых слов в наборе файлов PDF. Во-первых, мы должны определить отдельные слова и сопоставить их с моими ключевыми словами. Я нашел пример:
class MyLocationTextExtractionStrategy : LocationTextExtractionStrategy
{
//Hold each coordinate
public List<RectAndText> myPoints = new List<RectAndText>();
List<string> topicTerms;
public MyLocationTextExtractionStrategy(List<string> topicTerms)
{
this.topicTerms = topicTerms;
}
//Automatically called for each chunk of text in the PDF
public override void RenderText(TextRenderInfo renderInfo)
{
base.RenderText(renderInfo);
//Get the bounding box for the chunk of text
var bottomLeft = renderInfo.GetDescentLine().GetStartPoint();
var topRight = renderInfo.GetAscentLine().GetEndPoint();
//Create a rectangle from it
var rect = new iTextSharp.text.Rectangle(
bottomLeft[Vector.I1],
bottomLeft[Vector.I2],
topRight[Vector.I1],
topRight[Vector.I2]
);
//Add this to our main collection
//filter the meaingless words
string text = renderInfo.GetText();
this.myPoints.Add(new RectAndText(rect, renderInfo.GetText()));
Тем не менее, я обнаружил, что так много слов сломаны. Например, «стоп» будет «ст» и «оп». Есть ли другой способ определить отдельное слово и его позицию?
IsChunkAtWordBoundary()
, чтобы выяснить, должны ли два фрагмента быть одним словом. - person Chris Haas   schedule 16.12.2015