本文整理汇总了Java中edu.jhu.hlt.concrete.DependencyParse类的典型用法代码示例。如果您正苦于以下问题:Java DependencyParse类的具体用法?Java DependencyParse怎么用?Java DependencyParse使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DependencyParse类属于edu.jhu.hlt.concrete包,在下文中一共展示了DependencyParse类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: constructDependencyParses
import edu.jhu.hlt.concrete.DependencyParse; //导入依赖的package包/类
private List<DependencyParse> constructDependencyParses(UUID tokUuid) throws AnalyticException {
List<DependencyParse> depParseList = new ArrayList<>();
// possibly add a check if sg.size() == 0
this.basicDeps.ifPresent(sg -> {
LOGGER.debug("Generating DependencyParse from basic dependencies.");
depParseList.add(this.makeDepParse(sg, tokUuid, "Stanford CoreNLP basic"));
});
this.colDeps.ifPresent(sg -> {
LOGGER.debug("Generating DependencyParse from collapsed dependencies.");
depParseList.add(this.makeDepParse(sg, tokUuid, "Stanford CoreNLP col"));
});
this.colCCDeps.ifPresent(sg -> {
LOGGER.debug("Generating DependencyParse from collapsed-CC dependencies.");
depParseList.add(this.makeDepParse(sg, tokUuid, "Stanford CoreNLP col-CC"));
});
return depParseList;
}
示例2: makeDepParse
import edu.jhu.hlt.concrete.DependencyParse; //导入依赖的package包/类
private DependencyParse makeDepParse(int[] parents, List<String> depRels) {
if(depRels != null && parents.length != depRels.size()) {
throw new IllegalArgumentException("Parents length doesn't match depRels length");
}
DependencyParse p = new DependencyParse();
p.setUuid(getUUID());
AnnotationMetadata meta = new AnnotationMetadata();
meta.setTool(DEP_PARSE_TOOL);
meta.setTimestamp(timestamp);
p.setMetadata(meta);
p.setDependencyList(new ArrayList<Dependency>());
for(int i=0; i<parents.length; i++) {
if (parents[i] == -2) { continue; }
Dependency d = new Dependency();
d.setDep(i);
d.setGov(parents[i]);
if (depRels != null && depRels.get(i) != null) {
d.setEdgeType(depRels.get(i));
}
p.addToDependencyList(d);
}
return p;
}
示例3: makeDependencyParse
import edu.jhu.hlt.concrete.DependencyParse; //导入依赖的package包/类
private DependencyParse makeDependencyParse(SrlGraph srl, AnnoSentence from, AnnotationMetadata meta) {
DependencyParse p = new DependencyParse();
p.setUuid(getUUID());
p.setMetadata(meta);
p.setDependencyList(new ArrayList<Dependency>());
for(SrlPred pred : srl.getPreds()) {
{
Dependency d = new Dependency();
d.setGov(-1);
d.setDep(pred.getPosition());
d.setEdgeType(pred.getLabel());
p.addToDependencyList(d);
}
for(SrlEdge e : pred.getEdges()) {
Dependency ed = new Dependency();
ed.setGov(pred.getPosition());
ed.setDep(e.getArg().getPosition());
ed.setEdgeType(e.getLabel());
p.addToDependencyList(ed);
}
}
return p;
}
示例4: addDepParse
import edu.jhu.hlt.concrete.DependencyParse; //导入依赖的package包/类
private static void addDepParse(Tokenization tokenization, String toolName, int[] parents) {
List<Dependency> depList = new ArrayList<>();
int dep = 0;
for (int gov : parents) {
Dependency d = new Dependency();
d.setEdgeType("l"+dep);
d.setGov(gov);
d.setDep(dep++);
depList.add(d);
}
DependencyParse dp = new DependencyParse();
dp.setUuid(getUUID());
dp.setDependencyList(depList);
dp.setMetadata(getMetadata(toolName));
tokenization.addToDependencyParseList(dp);
}
示例5: makeDepParse
import edu.jhu.hlt.concrete.DependencyParse; //导入依赖的package包/类
private DependencyParse makeDepParse(SemanticGraph semGraph, UUID tokenizationUUID, String toolName) {
DependencyParse depParse = new DependencyParse();
depParse.setUuid(this.gen.next());
TheoryDependencies td = new TheoryDependencies();
td.addToTokenizationTheoryList(tokenizationUUID);
AnnotationMetadata md = new AnnotationMetadata(toolName, Timing.currentLocalTime(), 1);
depParse.setMetadata(md);
List<Dependency> dependencies = makeDependencies(semGraph);
depParse.setDependencyList(dependencies);
return depParse;
}
示例6: addStanfordAnalyticOutput
import edu.jhu.hlt.concrete.DependencyParse; //导入依赖的package包/类
/**
* Adds annotations to an already established {@link Sentence} object.
* <br>
* <br>
* Not consistent with the "return something new" paradigm - this mutates
* the passed in sentence object.
*
* @param st the {@link Sentence} to add annotations to
* @throws AnalyticException on error generating {@link Parse} or {@link DependencyParse}
*/
private void addStanfordAnalyticOutput(final Sentence st) throws AnalyticException {
Tokenization newTkz = st.getTokenization();
UUID tkzID = newTkz.getUuid();
List<DependencyParse> dpList = this.constructDependencyParses(tkzID);
dpList.forEach(dp -> newTkz.addToDependencyParseList(dp));
// cannot use functional style here b/c of checked ex.
if (this.tree.isPresent()) {
Parse p = makeConcreteCParse(tree.get(), newTkz.getTokenList().getTokenListSize(), tkzID, this.hf);
newTkz.addToParseList(p);
}
}
示例7: getObservedBasicDependencies
import edu.jhu.hlt.concrete.DependencyParse; //导入依赖的package包/类
public static Set<String> getObservedBasicDependencies(Communication c) {
Set<String> deps = new HashSet<>();
Assert.assertEquals(c.getSectionListSize(), 1);
Section sect = c.getSectionList().get(0);
Tokenization toks = sect
.getSentenceList().get(0).getTokenization();
Assert.assertNotNull(toks);
Assert.assertNotNull(toks.getDependencyParseList());
List<DependencyParse> dps = toks.getDependencyParseList()
.stream()
.filter(dp -> dp.getMetadata().getTool().contains("basic"))
.collect(Collectors.toList());
Assert.assertEquals(1, dps.size());
for (Dependency e : dps.get(0).getDependencyList()) {
Assert.assertTrue(e.getDep() >= 0);
List<Token> tokList = toks.getTokenList().getTokenList();
Token word = tokList.get(e.getDep());
String h = "ROOT-0";
if (e.isSetGov() && e.getGov() >= 0) {
h = String.format("%s-%d", tokList.get(e.getGov()).getText(), e.getGov() + 1);
}
String dep = String.format("%s(%s, %s-%d)",
e.getEdgeType(),
h,
word.getText(),
e.getDep() + 1);
deps.add(dep);
}
return deps;
}
示例8: getParentsDeprels
import edu.jhu.hlt.concrete.DependencyParse; //导入依赖的package包/类
private static Pair<int[],List<String>> getParentsDeprels(DependencyParse dependencyParse, int numWords) {
if (dependencyParse == null) {
return null;
}
// Parents.
int[] parents = new int[numWords];
Arrays.fill(parents, -2);
// Labels.
List<String> deprels = new ArrayList<>(numWords);
for (int i=0; i<numWords; i++) {
deprels.add(null);
}
for (Dependency arc : dependencyParse.getDependencyList()) {
// Parent.
int c = arc.getDep();
if (c < 0) {
throw new IllegalStateException(String.format("Invalid dep value %d for dependendency tree %s", arc.getDep(), dependencyParse.getUuid()));
}
if (parents[c] != -2) {
throw new IllegalStateException("Multiple parents for token: " + dependencyParse);
}
if (!arc.isSetGov()) {
parents[c] = -1;
} else {
parents[c] = arc.getGov();
}
// Label.
deprels.set(c, arc.getEdgeType());
}
if (IntArrays.contains(parents, -2)) {
log.trace("Dependency tree contains token(s) with no head: " + dependencyParse.getUuid());
}
return new Pair<int[],List<String>>(parents, deprels);
}
示例9: getFirstDependencyParseWithName
import edu.jhu.hlt.concrete.DependencyParse; //导入依赖的package包/类
public static DependencyParse getFirstDependencyParseWithName(Tokenization tokenization, String toolName) {
List<DependencyParse> parseList = tokenization.getDependencyParseList();
if (parseList == null) {
return null;
}
for (int i = 0; i < parseList.size(); i++) {
DependencyParse dp = parseList.get(i);
if (toolName == null || dp.getMetadata().getTool().contains(toolName)) {
return dp;
}
}
return null;
}
示例10: getFirstDependencyParseWithName
import edu.jhu.hlt.concrete.DependencyParse; //导入依赖的package包/类
/**
* Find the first DependencyParse in the
* given {@link Tokenization} whose tool name <em>contains</em>
* toolName. This throws a {@link ConcreteException} if no
* dependency parses containing the desired toolname are found.
*/
public DependencyParse getFirstDependencyParseWithName(Tokenization tokenization, String toolName) throws ConcreteException {
if (!tokenization.isSetDependencyParseList())
throw new ConcreteException("No DependencyParses for tokenization: " + tokenization.getUuid());
List<DependencyParse> parseList = tokenization.getDependencyParseList();
for (int i = 0; i < parseList.size(); i++) {
DependencyParse dp = parseList.get(i);
if(dp.getMetadata().getTool().contains(toolName))
return dp;
}
throw new ConcreteException("Did not find any dependency parses containing the string \""+toolName +"\" in tokenization " + tokenization.getUuid());
}
示例11: getDependencyParses
import edu.jhu.hlt.concrete.DependencyParse; //导入依赖的package包/类
@Override
public List<DependencyParse> getDependencyParses() {
return new ArrayList<>(this.depParseList);
}
示例12: getDependencyParses
import edu.jhu.hlt.concrete.DependencyParse; //导入依赖的package包/类
@Override
public List<DependencyParse> getDependencyParses() {
return this.preNER.getDependencyParses();
}
示例13: getAnnoSentence
import edu.jhu.hlt.concrete.DependencyParse; //导入依赖的package包/类
private AnnoSentence getAnnoSentence(Tokenization tokenization) {
TokenizationKind kind = tokenization.getKind();
if (kind != TokenizationKind.TOKEN_LIST) {
throw new IllegalArgumentException("tokens must be of kind TOKEN_LIST: " + kind);
}
AnnoSentence as = new AnnoSentence();
// Words
List<String> words = new ArrayList<String>();
TokenList tl = tokenization.getTokenList();
for (Token tok : tl.getTokenList()) {
words.add(tok.getText());
}
as.setWords(words);
// POS tags, Lemmas, and Chunks.
TokenTagging posTags = ConcreteUtils.getFirstXTagsWithName(tokenization, TagTypes.POS.name(), prm.posTool);
TokenTagging cposTags = ConcreteUtils.getFirstXTagsWithName(tokenization, TagTypes.POS.name(), prm.cposTool);
TokenTagging lemmas = ConcreteUtils.getFirstXTagsWithName(tokenization, TagTypes.LEMMA.name(), prm.lemmaTool);
TokenTagging chunks = ConcreteUtils.getFirstXTagsWithName(tokenization, "CHUNK", prm.chunkTool);
as.setPosTags(getTagging(posTags));
as.setCposTags(getTagging(cposTags));
as.setLemmas(getTagging(lemmas));
as.setChunks(getTagging(chunks));
// Dependency Parse
if (tokenization.isSetDependencyParseList()) {
int numWords = words.size();
log.trace("Reading dependency parse with name {}", prm.depParseTool);
DependencyParse depParse = ConcreteUtils.getFirstDependencyParseWithName(tokenization, prm.depParseTool);
Pair<int[], List<String>> pair = getParentsDeprels(depParse, numWords);
if (pair != null) {
as.setParents(pair.get1());
as.setDeprels(pair.get2());
}
}
// Constituency Parse
if (tokenization.isSetParseList()) {
NaryTree tree = getParse(ConcreteUtils.getFirstParseWithName(tokenization, prm.parseTool ));
as.setNaryTree(tree);
}
return as;
}
示例14: getFirstDependencyParse
import edu.jhu.hlt.concrete.DependencyParse; //导入依赖的package包/类
public static DependencyParse getFirstDependencyParse(Tokenization tokenization) {
return getFirstDependencyParseWithName(tokenization, null);
}
示例15: create
import edu.jhu.hlt.concrete.DependencyParse; //导入依赖的package包/类
/**
* @return a {@link DependencyParse} with a Concrete {@link UUID} set
*/
public final DependencyParse create() {
return new DependencyParse()
.setUuid(this.gen.next());
}