java - Replacing digits with Noun using hash map -


my input sentence is:

ram you

after parse tree:

' 2|type|nx0e-vpadjn-vnx1 1|rpron|nx-rp-s 0|noun|nxn 3|noun|nxn ', '1' 

i want replace 2 'are' 1 'where' , ram 0 .

how should hash map?

this answer based on lot of assumptions question not clear enough. not have enough rep comment.

if use string.split() on input sentence as:

string[] words = "ram you".split(" "); // words[0] => ram // words[1] => // words[2] => // words[3] => 

it appears parse tree generated parsing input sentence.
each entry in first section of parse tree corresponds word in input sentence.
first digit in parse entry seems correspond index of each word in input sentence.

so parse entry can broken as: <word index>|<word category>|<something not clear>

so, seems

2|type|nx0e-vpadjn-vnx1 => 1|rpron|nx-rp-s => 0|noun|nxn => ram 3|noun|nxn => 

based on these assumptions possible use hashmap built using parse tree entries.
need put parse entries in map using key = <word index>; value = <parse entry>.
can done separating parse tree entries , retrieving <word index> each entry.

once map built can process input sentence , parse tree entries as:

string[] words = "ram you".split(" ");  map<integer, string> entriesmap = getentriesmap(parsetree); // assuming parsetree string  for(int = 0; < words.length; i++) {     string x = entriesmap.get(i).replaceall("^" + + "|", words[i]); } 

method populate map. there multiple ways this.
use of pattern , matcher classes proper regex best way.

private map<integer, string> getentriesmap(string parsetree) {     map<integer, string> entriesmap = new linkedhashmap<integer, string>();      // assuming parsetree format as: '<parse entries separated spaces>', '1'     // use string.split() split parsetree single quote (')     // first element in returning array contain <parse entries separated spaces>     // use string.split() again on element space separate parse entries     // each <entry> in <parse entries>     //     split <entry> pipe (|) , use first element in resulting array key , <entry> value put in entriesmap      return entriesmap; } 

can not figure out ,'1' @ end of parse tree corresponds to.


Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -