Ein Beispiel für die Verwendung von Extraktionsskripten

Ein Beispiel für die Verwendung von Extraktionsskripten in C#

FieldExtractor.ExtractRegularExpression( "(grant(s))|(convey to)|(grant)", "keyWords" );
FieldExtractor.ExtractWordsFromUserDictionary("dictionary", "English");
FieldExtractor.ExtractNerObjects();
// Zugriff auf identifizierte Objekte nach Sammlungsname
IExtractedObjects personObjects = FieldExtractor.ExtractedObjects( "NerPerson" );
IExtractedObjects keyWordsObjects = FieldExtractor.ExtractedObjects( "keyWords" );
// Suche nach übereinstimmender Person links vom Schlüsselwort
for( int i = 0; i < keyWordsObjects.Count; i++ ) {
   IExtractedObject keyWord = personObjects.Item( i );
   IInterval span = keyWord.Span;
   IExtractedObject grantor = personObjects.Find( span.StartPos, false );
   string grantorName = grantor.Value;
   if ( grantorName.Length > 2 && grantorName != "Doug Darrell" ) {
       FieldExtractor.PutSpanToField( grantor.Span, "NlpField1" );
   }
}
// Zugriff auf Quelltest
string sourceText = FieldExtractor.SourceText;
// Text in das Feld schreiben
FieldExtractor.PutTextToField( 0, sourceText.Length - 1, "NlpField2" );
// Eine XML-Abfrage, die nach Wörterbuchwortgruppen aus zwei Buchstaben sucht
string query = "<Request> " +
   "<Query>" +
       "<Contain MaxDistance=\"1\">" +
           "<Required>" +
               "<Form><Attributes><Attribute>dictionary1</Attribute></Attributes></Form>" +
           "</Required>" +
           "<Required>" +
                "<Form><Attributes><Attribute>dictionary2</Attribute></Attributes></Form>" +
           "</Required>" +
       "</Contain>" +
   "</Query>" +
"</Request>";
// Abfrage ausführen, Ergebnissammlung erhalten und in Feld speichern
FieldExtractor.RunQueryAndSaveToField( query, "query1", "NlpField3");
// Abfrage ausführen und Sammlung von Ergebnissen erhalten    
IExtractedObjects queryResults1 = FieldExtractor.RunQuery( query, "query2" );
// Eine alternative Methode für den Zugriff auf Abfrageergebnisse nach dem Ausführen der Abfrage
IExtractedObjects queryResults2 = FieldExtractor.QueryResults( "query2" );

Skriptparameter

Name Typ Berechtigungen Wert
FieldExtractor IFieldExtractor Lesen Identifiziert Felder im Text eines Dokuments

Musterskript für die Adressextraktion

Das Skript wird für das gesamte Quellfeld aufgerufen.

// Analysieren der Adresse
this.ParseAddress();
// Extrahieren der Komponenten in getrennte Felder
var zip = this.ExtractedObjects( "NerZipCode" );
var street = this.ExtractedObjects( "NerStreet" );
für( var i = 0; i < zip.Count; i++ ) {
    this.PutSpanToField( zip.Item(i).Span, "ZipCode" );
}
for( var j = 0; j < street.Count; j++ ) {
    this.PutSpanToField( street.Item(j).Span, "Street" );
}

Musterskript für die Adressextraktion

Das Skript wird für einen Teil des Quellfeldes aufgerufen.

 // Erkennen aller NER-Objekte im Text des Feldes oder Bereichs
this.ExtractNerObjects();
 // Extrahieren des Objekts der Adresse
var address = this.ExtractedObjects( "NerAddress" );
 // Aufteilung der Adressen in Komponenten
for( var addressSpanIndex = 0; addressSpanIndex < address.Count; addressSpanIndex++ ) {
    this.PutSpanToField( address.Item(addressSpanIndex).Span, "Address" );
  // Zuweisung der Namen aller Komponentensammlungen für die gegebene Adresse an ein eindeutiges Präfix
  var collectionName = "nerAddress" + String(addressSpanIndex);
  // Extrahieren der Adresse
  this.ParseAddressInPosition( collectionName, address.Item(addressSpanIndex).Span.StartPos, address.Item(addressSpanIndex).Span.EndPos );
  // Speichern der Komponenten in getrennten Feldern
  var zip = this.ExtractedObjects( collectionName, "NerZipCode" );
  var street = this.ExtractedObjects( collectionName, "NerStreet" );
 RunQueryAndSaveToField
  für( var i = 0; i < zip.Count; i++ ) {
        this.PutSpanToField( zip.Item(i).Span, "ZipCode" );
 }
  for( var j = 0; j < street.Count; j++ ) {
        this.PutSpanToField( street.Item(j).Span, "Street" );
 }
}

25.05.2023 7:55:00

Please leave your feedback about this article

Usage of Cookies. In order to optimize the website functionality and improve your online experience ABBYY uses cookies. You agree to the usage of cookies when you continue using this site. Further details can be found in our Privacy Notice.