/** * Returns true if this constituent contains no sub-constituents. * * @return true if this constituent contains no sub-constituents; false otherwise. */ public boolean isFlat() { boolean flat = true; for (int ci = 0; ci < parts.size(); ci++) { flat &= (parts.get(ci)).isPosTag(); } return flat; }
/** * Returns the parse nodes which are children of this node and which are pos tags. * * @return the parse nodes which are children of this node and which are pos tags. */ public Parse[] getTagNodes() { List<Parse> tags = new LinkedList<>(); List<Parse> nodes = new LinkedList<>(); nodes.addAll(this.parts); while (nodes.size() != 0) { Parse p = nodes.remove(0); if (p.isPosTag()) { tags.add(p); } else { nodes.addAll(0,p.parts); } } return tags.toArray(new Parse[tags.size()]); }
private static void getInitialChunks(Parse p, List<Parse> ichunks) { if (p.isPosTag()) { ichunks.add(p); } else { Parse[] kids = p.getChildren(); boolean allKidsAreTags = true; for (int ci = 0, cl = kids.length; ci < cl; ci++) { if (!kids[ci].isPosTag()) { allKidsAreTags = false; break; } } if (allKidsAreTags) { ichunks.add(p); } else { for (int ci = 0, cl = kids.length; ci < cl; ci++) { getInitialChunks(kids[ci], ichunks); } } } }
private static void getInitialChunks(Parse p, List<Parse> ichunks) { if (p.isPosTag()) { ichunks.add(p); } else { Parse[] kids = p.getChildren(); boolean allKidsAreTags = true; for (int ci = 0, cl = kids.length; ci < cl; ci++) { if (!kids[ci].isPosTag()) { allKidsAreTags = false; break; } } if (allKidsAreTags) { ichunks.add(p); } else { for (int ci = 0, cl = kids.length; ci < cl; ci++) { getInitialChunks(kids[ci], ichunks); } } } }
private void addTagEvents(List<Event> tagEvents, Parse[] chunks) { List<String> toks = new ArrayList<>(); List<String> preds = new ArrayList<>(); for (int ci = 0, cl = chunks.length; ci < cl; ci++) { Parse c = chunks[ci]; if (c.isPosTag()) { toks.add(c.getCoveredText()); preds.add(c.getType()); } else { Parse[] kids = c.getChildren(); for (int ti = 0, tl = kids.length; ti < tl; ti++) { Parse tok = kids[ti]; toks.add(tok.getCoveredText()); preds.add(tok.getType()); } } } for (int ti = 0, tl = toks.size(); ti < tl; ti++) { tagEvents.add(new Event(preds.get(ti), tagContextGenerator.getContext(ti, toks.toArray(new String[toks.size()]), preds.toArray(new String[preds.size()]), null))); } }
for (int ci = 0, cl = chunks.length; ci < cl; ci++) { Parse c = chunks[ci]; if (c.isPosTag()) { toks.add(c.getCoveredText()); tags.add(c.getType());
/** * Returns the right frontier of the specified parse tree with nodes ordered from deepest * to shallowest. * @param root The root of the parse tree. * @return The right frontier of the specified parse tree. */ public static List<Parse> getRightFrontier(Parse root,Set<String> punctSet) { List<Parse> rf = new LinkedList<>(); Parse top; if (AbstractBottomUpParser.TOP_NODE.equals(root.getType()) || AbstractBottomUpParser.INC_NODE.equals(root.getType())) { top = collapsePunctuation(root.getChildren(),punctSet)[0]; } else { top = root; } while (!top.isPosTag()) { rf.add(0,top); Parse[] kids = top.getChildren(); top = kids[kids.length - 1]; } return new ArrayList<>(rf); }
/** * Obtain {@code Span}s for every parse in the sentence. * @param parse the parse from which to obtain the spans * @return an array containing every span for the parse */ private static Span[] getConstituencySpans(final Parse parse) { Stack<Parse> stack = new Stack<>(); if (parse.getChildCount() > 0) { for (Parse child : parse.getChildren()) { stack.push(child); } } List<Span> consts = new ArrayList<>(); while (!stack.isEmpty()) { Parse constSpan = stack.pop(); if (!constSpan.isPosTag()) { Span span = constSpan.getSpan(); consts.add(new Span(span.getStart(), span.getEnd(), constSpan.getType())); for (Parse child : constSpan.getChildren()) { stack.push(child); } } } return consts.toArray(new Span[consts.size()]); }
for (int ci = 0, cl = chunks.length; ci < cl; ci++) { Parse c = chunks[ci]; if (c.isPosTag()) { toks.add(c.getCoveredText()); tags.add(c.getType());
public boolean isToken() { return parse.isPosTag(); }
public boolean isToken() { return parse.isPosTag(); }
int off = 0; if (!chunks[ci].isPosTag()) { builtNodes.add(off++,chunks[ci]);
if (children[0].isPosTag()) { return null;
/** * Returns true if this constituent contains no sub-constituents. * * @return true if this constituent contains no sub-constituents; false otherwise. */ public boolean isFlat() { boolean flat = true; for (int ci = 0; ci < parts.size(); ci++) { flat &= (parts.get(ci)).isPosTag(); } return flat; }
/** * Returns true if this constituent contains no sub-constituents. * * @return true if this constituent contains no sub-constituents; false otherwise. */ public boolean isFlat() { boolean flat = true; for (int ci = 0; ci < parts.size(); ci++) { flat &= (parts.get(ci)).isPosTag(); } return flat; }
public static boolean allChildNodesArePOSTags(Parse p) { Parse[] subParses = p.getChildren(); for (int pi = 0; pi < subParses.length; pi++) if (!((Parse) subParses[pi]).isPosTag()) return false; return true; }
public List<opennlp.tools.coref.mention.Parse> getTokens() { List<Parse> tokens = new ArrayList<Parse>(); List<Parse> kids = new LinkedList<Parse>(Arrays.asList(parse.getChildren())); while (kids.size() > 0) { Parse p = kids.remove(0); if (p.isPosTag()) { tokens.add(p); } else { kids.addAll(0,Arrays.asList(p.getChildren())); } } return createParses(tokens.toArray(new Parse[tokens.size()])); }
public List<opennlp.tools.coref.mention.Parse> getTokens() { List<Parse> tokens = new ArrayList<Parse>(); List<Parse> kids = new LinkedList<Parse>(Arrays.asList(parse.getChildren())); while (kids.size() > 0) { Parse p = kids.remove(0); if (p.isPosTag()) { tokens.add(p); } else { kids.addAll(0,Arrays.asList(p.getChildren())); } } return createParses(tokens.toArray(new Parse[tokens.size()])); }
@Test public void testGetTagNodes() { Parse p = Parse.parseParse(PARSE_STRING); Parse[] tags = p.getTagNodes(); for (Parse node : tags) { Assert.assertTrue(node.isPosTag()); } Assert.assertEquals("PRP", tags[0].getType()); Assert.assertEquals("VBD", tags[1].getType()); Assert.assertEquals("RB", tags[2].getType()); Assert.assertEquals("DT", tags[3].getType()); Assert.assertEquals("NN", tags[4].getType()); Assert.assertEquals("IN", tags[5].getType()); Assert.assertEquals("DT", tags[6].getType()); Assert.assertEquals("NNPS", tags[7].getType()); Assert.assertEquals(",", tags[8].getType()); Assert.assertEquals("CC", tags[9].getType()); Assert.assertEquals("PRP", tags[10].getType()); Assert.assertEquals("VBD", tags[11].getType()); Assert.assertEquals("RB", tags[12].getType()); Assert.assertEquals("JJ", tags[13].getType()); Assert.assertEquals("IN", tags[14].getType()); Assert.assertEquals("PRP$", tags[15].getType()); Assert.assertEquals("NN", tags[16].getType()); Assert.assertEquals(".", tags[17].getType()); } }