I have used the parser in the gate to get the dependency. And from that dependency, I found separate list for the dependency pair and dependency name.
My input is
String idlist =[26, 28]
String argslist = [[26, 25], [26, 24], [26, 29], [26, 28], [28, 27], [35, 26], [29, 30]]
String kindlist =[ aux, dobj, pobj, prep, advmod, aux, adj]
My expected output is two list
Depflowlist is first one and another one kindflowlist.
for 26 itself it has different flow.
for 26 expected depflowlist is [26, 25] and its corresponding kindflowlist [aux]
then [26, 24] is another depflowlist for 26 and its corresponding kindflowlist [dobj]
then [[26, 29] ,[29, 30]] is another depflowlist for 26 and its corresponding kindflowlist [pobj, adj].
This should be done for 28 also.
I have write the code like :
`public static void dependencyparse(String a,ArrayList<String> argslist,ArrayList<String> kindlist,Document doc){
ArrayList<String> selectarg_list = new ArrayList<String>();
for(int j=0;j<argslist.size();j++)
{
int index=argslist.get(j).indexOf(a);
if(index==1)
{
String next=argslist.get(j).substring(5, 7);
selectarg_list.add(next);
}
}
System.out.println(a+"---------->"+selectarg_list);
if(!selectarg_list.isEmpty())
{
// System.out.println("notempty");
hm.put(a, selectarg_list);
}
//System.out.println("Hashmap"+hm);
if(selectarg_list.size()>0){
dependencyparse(selectarg_list.get(0),argslist,kindlist,doc);
}
if(selectarg_list.size()==0){
String prevKey = delete(a,selectarg_list,argslist,kindlist,doc);
System.out.println(prevKey);
if(!hm.isEmpty()){
if(hm.keySet().contains(prevKey)){
ArrayList<String> list = hm.get(prevKey);
dependencyparse(list.get(0),argslist,kindlist,doc);
}
else{
if(!hm.isEmpty()){
try{
dependencyparse(hm.values().iterator().next().get(0), argslist, kindlist,doc);
}catch (Exception e) {}
}
}
Iterator<String> itr3 = hm.keySet().iterator();
while (itr3.hasNext()) {
String string = (String) itr3.next();
System.out.println(string+"------------>"+hm.get(string));
}
}
}
}
private static String delete(String a,ArrayList<String> selectarg_list,ArrayList<String> argslist,ArrayList<String> kindlist,Document doc) {
AnnotationSet outputAnnotations=doc.getNamedAnnotationSets().get("Output markups");
String retKey="";
Collection<ArrayList<String>> values = hm.values();
String key="";
//System.out.println("Valuess"+values);
//System.out.println("find"+a);
boolean flag=false;
Iterator<ArrayList<String>> Valueitr = values.iterator();
while(Valueitr.hasNext())
{
//System.out.println("Valuess---->"+Valueitr.next());
ArrayList<String> contentnext = Valueitr.next();
if(contentnext.contains(a))
{
flag=true;
//System.out.println("Valuess find---->"+contentnext);
for(Entry<String, ArrayList<String>> entry : hm.entrySet())
{
if(contentnext.equals(entry.getValue()))
{
key = entry.getKey();
// System.out.println("Key find---->"+key);
// do something with the key
String arg = "["+key+", "+a+"]";
// System.out.println("arg find---->"+arg);
depFlowList.addFirst(arg);
// System.out.println("entry find---->"+entry.getValue());
try{
if(!hm.keySet().contains(a)){
entry.getValue().remove(a);
// hm.put(entry.getKey(), value)
// System.out.println(entry.getKey()+"----------------"+hm.get(entry.getKey())+"
entry delete---->"+entry.getValue());
}}catch (Exception e) { }
}
}
}
}
if(!flag){
if(!depFlowList.isEmpty()){
System.out.println("Dep Flow List----->"+depFlowList);
for(int x=0;x<depFlowList.size();x++){
String item=depFlowList.get(x);
int item_index=argslist.indexOf(item);
String item_kind=kindlist.get(item_index);
System.out.println("adding kind of -----"+depFlowList.get(x));
kindFlowList.add(item_kind);
}
System.out.println("Kind Flow List----->"+kindFlowList);
file_write("/home/cognicor/vagateplugin/testing/dependency.txt",kindFlowList.toString());
}
if(!kindFlowList.isEmpty()){
FeatureMap depfeature = new SimpleFeatureMapImpl();
depfeature.put("depflow", kindFlowList);
try {
outputAnnotations.add(new Long(0),new Long(1), "DependencyFlow",depfeature);
} catch (InvalidOffsetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if(depFlowList.size()==0){
return "";
}
retKey=depFlowList.getLast().substring(1,3);
depFlowList.clear();
kindFlowList.clear();
System.out.println(retKey);
return retKey;
}
//System.out.println("++++++++++++++++++++++++++++++++++++++++++++++");
ArrayList<String> findval = hm.get(key);
if(findval.isEmpty()){
hm.remove(key);
//System.out.println("key removed");
}
//if(!hm.isEmpty()){
retKey=delete(key, selectarg_list, argslist, kindlist,doc);
return retKey;
//}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
ArrayList<String> testlist = file_read("/home/cognicor/vagateplugin/testing/testing_set1.txt");
//System.out.println(testlist);
ArrayList<String> query_class = new ArrayList<String>();
ArrayList<String> property_class = new ArrayList<String>();
Iterator<String> testinput = testlist.iterator();
String entry;
System.out.println("testlist---->"+testlist);
for(int i=0;i<testlist.size();i++)
{
try {
ArrayList<Integer> idlist = new ArrayList<Integer>();
ArrayList<String> argslist = new ArrayList<String>();
ArrayList<String> kindlist = new ArrayList<String>();
String query = "<currDial>"+testlist.get(i)+"</currDial>";
System.out.println(query);
Document doc = pipline.get_Annoted_Doument(query);
/* code where i get the input like idlist, arglist and kindlist*/
AnnotationSet annotset = doc.getNamedAnnotationSets().get("Output markups").get("TokenID");
Iterator<Annotation> itr = annotset.iterator();
while(itr.hasNext())
{
Annotation annot = itr.next();
int id = (int) annot.getFeatures().get("id");
idlist.add(id);
}
AnnotationSet annotset1 = doc.getNamedAnnotationSets().get("Output markups").get("Dependency");
Iterator<Annotation> itr1 = annotset1.iterator();
while(itr1.hasNext())
{
Annotation annot = itr1.next();
String arg = annot.getFeatures().get("args").toString();
String kind = annot.getFeatures().get("kind").toString();
argslist.add(arg);
kindlist.add(kind);
}
System.out.println("args"+argslist);
for(int j=0;j<idlist.size();j++)
{
System.out.println("-------------------------------Item:"+idlist.get(j).toString()+"------------------------------------------");
dependencyparse(idlist.get(j).toString(),argslist,kindlist,doc);
if(j==idlist.size())
{
dependencyparse("null",argslist,kindlist,doc);
}
}
}catch(Exception e) { e.printStackTrace(); }
}
}
}`
Now I got a loop which is not ending . I am using the output from the gate.
See Question&Answers more detail:
os