我现在正在使用Stanford CoreNLP和Fudan NLP处理中文自然语言。这两个工具都生成了解析树,即Stanford CoreNLP Parse Tree
和Fudan NLP Parse Tree
(让我称之为STree
和FTree
)。
我需要使用STree
和FTree
,并对它们执行一些伪装的方法,这些方法共享相同的函数签名和各种实现细节。因此,最佳做法是定义一个可以从STree
和FTree
生成的类。
然而,这两种解析树在数据结构方面完全不同。所以我可以想到两个解决方案:
定义具有泛型类型的类Tree
,该类将按内容类型STree
和FTree
传递。加上TreeFactory
然后传递这两种内容类型并生成相对树。如果我按照这种方式,我不能拆分相同方法的两种实现。
定义一个接口或抽象类Tree
,其中包含多个方法。然后将此接口扩展为与STree
和FTree
对应的两个不同的子类。如果我遵循这种方式,子类中的children
将不是super.children
的子类。
class TreeNode {
List<TreeNode> children;
//...
};
class STree extends TreeNode {
List<STree> children; // Problem: not a subclass of super.children
//...
};
class FTree extends TreeNode {
List<FTree> children; // Problem: not a subclass of super.children
//...
};
我想知道哪个是更好的选择。或者任何人都可以提供更具适应性的解决方案。
以下是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;
// ...
};
STree
的定义:
// Definition edu.stanford.nlp.trees.LabeledScoredTreeNode
public class LabeledScoredTreeNode extends Tree {
// Label of the parse tree.
private Label label; // = null;
// Score of <code>TreeNode</code>
private double score = Double.NaN;
// Daughters of the parse tree.
private Tree[] daughterTrees; // = null;
// ...
};
答案 0 :(得分:1)
我认为更基本的问题是你将如何使用来自两个不同解析器的句法分析结果。由于两棵树的结构可能完全不同,我不确定你将如何使用两个解析器结果或部分语音级别!
另一个可能的选择是,如果你在句子中的每个单词上做注释,你可以结合Standford NLP工具和FudanNLP工具的输出。
从技术上讲,总是可以使用Mike建议的选项来获得具有STreeMetaModelNode和FTreeMetaModelNode的具体实现类的MetaModelNode接口。