uimaruta

extract text from indented text file using ruta


Using Ruta, I'm trying to extract data from text file. I have tried few approaches but not able to get exact required information. I need to fetch Borrower Name from indented text file.

Example:

Borrower Name: Alice                             SSN: 000-00-000  
Co-Borrower Name:                                SSN:

I annotated Borrower Name keyword and SSN keyword but not able to figure out query to get name.

Document{->RETAINTYPE(SPACE)};
DECLARE BorrowerKeyword, NameKeyword, BorrowerNameKeyword;
W{REGEXP("Borrower")->BorrowerKeyword};
W{REGEXP("Name")->NameKeyword};

(SPACE BorrowerKeyword SPACE NameKeyword){-> BorrowerNameKeyword};

DECLARE SSNKeyword;
W{REGEXP("SSN")->SSNKeyword};
DECLARE BorrowerNameLine;
Line{CONTAINS(BorrowerNameKeyword,10,100),
     CONTAINS(SSNKeyword,10,50)-> MARK(BorrowerNameLine)}; // Not able to annotate BorrowerNameLine


// other way but that also didn't work.
DECLARE BorrowerName;
RETAINTYPE(SPACE);
CW.ct=="Borrower" CW.ct=="Name" COLON n:W{-> CREATE(BorrowerName, "label"="Borrower Name", "value"=n.ct)};
RETAINTYPE;

Please suggest what I have missed and correct query


Solution

  • Try to filter the SPACE out after usage to avoid any undesired effects and to ease the rule development.

    REMOVERETAINTYPE(SPACE);
    DECLARE Borrower, Name; 
    CW{REGEXP("\\bBorrower") -> Borrower} CW{REGEXP("Name") -> Name};
    Borrower Name COLON n:W{-> CREATE(BorrowerName, "label"="Borrower Name", "value"=n.ct)};