本文整理匯總了Java中edu.jhu.hlt.concrete.Parse類的典型用法代碼示例。如果您正苦於以下問題:Java Parse類的具體用法?Java Parse怎麽用?Java Parse使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Parse類屬於edu.jhu.hlt.concrete包,在下文中一共展示了Parse類的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: makeConcreteCParse
import edu.jhu.hlt.concrete.Parse; //導入依賴的package包/類
/**
* Whenever there's an empty parse, this method will set the required
* constituent list to be an empty list. It's up to the caller on what to do
* with the returned Parse.
*
* @param n
* is the number of tokens in the sentence
*
* @throws AnalyticException
*/
private Parse makeConcreteCParse(Tree root, int n, UUID tokenizationUUID, HeadFinder hf) throws AnalyticException {
int left = 0;
int right = root.getLeaves().size();
if (right != n)
throw new AnalyticException("number of leaves in the parse (" + right + ") is not equal to the number of tokens in the sentence (" + n + ")");
Parse p = new ParseFactory(this.gen).create();
TheoryDependencies deps = new TheoryDependencies();
deps.addToTokenizationTheoryList(tokenizationUUID);
AnnotationMetadata md = new AnnotationMetadata("Stanford CoreNLP", Timing.currentLocalTime(), 1);
p.setMetadata(md);
constructConstituent(root, left, right, n, p, tokenizationUUID, hf);
if (!p.isSetConstituentList()) {
LOGGER.warn("Setting constituent list to compensate for the empty parse for tokenization id {} and tree {}", tokenizationUUID, root);
p.setConstituentList(new ArrayList<Constituent>());
}
return p;
}
示例2: addParse
import edu.jhu.hlt.concrete.Parse; //導入依賴的package包/類
private static void addParse(Tokenization tokenization, String toolName, String tagPrefix) {
int n = tokenization.getTokenList().getTokenListSize();
List<Constituent> cList = new ArrayList<>();
for (int i=0; i<n; i++) {
Constituent c = new Constituent();
c.setStart(i);
c.setEnding(n);
if (i < n-1) {
c.setChildList(QLists.getList(i+1));
} else {
c.setChildList(new ArrayList<Integer>());
}
c.setHeadChildIndex(i);
c.setTag(tagPrefix+i);
c.setId(i);
cList.add(c);
}
Parse p = new Parse();
p.setUuid(getUUID());
p.setMetadata(getMetadata(toolName));
p.setConstituentList(cList);
tokenization.addToParseList(p);
}
示例3: addStanfordAnalyticOutput
import edu.jhu.hlt.concrete.Parse; //導入依賴的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);
}
}
示例4: getFirstParseWithName
import edu.jhu.hlt.concrete.Parse; //導入依賴的package包/類
public static Parse getFirstParseWithName(Tokenization tokenization, String toolName) {
List<Parse> parseList = tokenization.getParseList();
if (parseList == null) {
return null;
}
for (int i = 0; i < parseList.size(); i++) {
Parse p = parseList.get(i);
if (toolName == null || p.getMetadata().getTool().contains(toolName)) {
return p;
}
}
return null;
}
示例5: constructConstituent
import edu.jhu.hlt.concrete.Parse; //導入依賴的package包/類
/**
*
* @param root
* @param left
* @param right
* @param n
* is the length of the sentence is tokens.
* @param p
* @param tokenizationUUID
* @return The constituent ID
* @throws AnalyticException
*/
private static int constructConstituent(Tree root, int left,
int right, int n, Parse p, UUID tokenizationUUID, HeadFinder hf)
throws AnalyticException {
Constituent constituent = new Constituent();
constituent.setId(p.getConstituentListSize());
constituent.setTag(root.value());
constituent.setStart(left);
constituent.setEnding(right);
p.addToConstituentList(constituent);
Tree headTree = null;
if (!root.isLeaf()) {
try {
headTree = hf.determineHead(root);
} catch (java.lang.IllegalArgumentException iae) {
LOGGER.warn("Failed to find head, falling back on rightmost constituent.", iae);
headTree = root.children()[root.numChildren() - 1];
}
}
int i = 0, headTreeIdx = -1;
int leftPtr = left;
for (Tree child : root.getChildrenAsList()) {
int width = child.getLeaves().size();
int childId = constructConstituent(child, leftPtr, leftPtr
+ width, n, p, tokenizationUUID, hf);
constituent.addToChildList(childId);
leftPtr += width;
if (headTree != null && child == headTree) {
assert (headTreeIdx < 0);
headTreeIdx = i;
}
i++;
}
if (headTreeIdx >= 0)
constituent.setHeadChildIndex(headTreeIdx);
if (!constituent.isSetChildList())
constituent.setChildList(new ArrayList<Integer>());
return constituent.getId();
}
示例6: getFirstParse
import edu.jhu.hlt.concrete.Parse; //導入依賴的package包/類
public static Parse getFirstParse(Tokenization tokenization) {
return getFirstParseWithName(tokenization, null);
}
示例7: create
import edu.jhu.hlt.concrete.Parse; //導入依賴的package包/類
/**
* @return a {@link Parse} with a {@link UUID} set
*/
public final Parse create() {
return new Parse().setUuid(this.gen.next());
}
示例8: getParses
import edu.jhu.hlt.concrete.Parse; //導入依賴的package包/類
public List<Parse> getParses();