java - How to integrate two Parse Tree data structures from two different NLP Tools -
i using both stanford corenlp , fudan nlp process chinese natural language. these 2 tools both generate parse tree, i.e. stanford corenlp parse tree
, fudan nlp parse tree
(let me call them stree
, ftree
).
and need make use of stree
, ftree
, , costumed method on them, sharing same function signature , various in implement details. best practice define class can generate both stree
, ftree
.
however, these 2 kind of parse tree totally different in aspect of data structure. can think of 2 solutions:
define class
tree
generic type, passed content type ofstree
,ftree
. plustreefactory
pass these 2 kind of content types , generate relative trees. if follow way, cannot take apart 2 kind of implementation of same method.define interface or abstract class
tree
, contains several methods. extend interface 2 different subclass correspondingstree
,ftree
. if follow way,children
in subclasses not subclass ofsuper.children
.class treenode { list<treenode> children; //... }; class stree extends treenode { list<stree> children; // problem: not subclass of super.children //... }; class ftree extends treenode { list<ftree> children; // problem: not subclass of super.children //... };
i wonder better choice. or can provide more adaptable solution.
following brief definition of ftree
:
// declaration edu.fudan.nlp.parser.dep.dependencytree; public class dependencytree implements serializable { // tree node content public string word; public string pos; // sequence number in sentence public int id; private int size=1; // dependancy relation type public string relation; public list<dependencytree> leftchilds; public list<dependencytree> rightchilds; private dependencytree parent = null; // ... };
definition of stree
:
// definition edu.stanford.nlp.trees.labeledscoredtreenode public class labeledscoredtreenode extends tree { // label of parse tree. private label label; // = null; // score of <code>treenode</code> private double score = double.nan; // daughters of parse tree. private tree[] daughtertrees; // = null; // ... };
i think more fundamental question how going use syntactic analysis result 2 different parsers. 2 trees totally different in structure , not sure how going use 2 parsers result or part of speech level!
another possible option if doing annotation on each word in sentence, can combine output standford nlp tool , fudannlp tool.
technically it's possible use option suggested mike have metamodelnode interface concrete implementation classes of streemetamodelnode , ftreemetamodelnode.
Comments
Post a Comment