public Parse parse(Parse tokens) { if (tokens.getChildCount() > 0) { Parse p = parse(tokens,1)[0]; setParents(p); return p; } else { return tokens; } }
/** * 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()]); }
completeParses.clear(); int derivationStage = 0; //derivation length int maxDerivationLength = 2 * tokens.getChildCount() + 3; odh.add(tokens); Parse guess = null;
protected void process(CAS cas, AnnotationFS sentenceAnnotation) { FSIndex<AnnotationFS> allTokens = cas.getAnnotationIndex(mTokenType); ContainingConstraint containingConstraint = new ContainingConstraint(sentenceAnnotation); String sentence = sentenceAnnotation.getCoveredText(); Iterator<AnnotationFS> containingTokens = cas.createFilteredIterator( allTokens.iterator(), containingConstraint); List<Span> tokenSpans = new LinkedList<>(); while (containingTokens.hasNext()) { AnnotationFS token = containingTokens.next(); tokenSpans.add(new Span(token.getBegin() - sentenceAnnotation.getBegin(), token.getEnd() - sentenceAnnotation.getBegin())); } ParseConverter converter = new ParseConverter(sentence, tokenSpans.toArray(new Span[tokenSpans.size()])); Parse unparsedTree = converter.getParseForTagger(); if (unparsedTree.getChildCount() > 0) { Parse parse = mParser.parse(unparsedTree); // TODO: We need a strategy to handle the case that a full // parse could not be found. What to do in this case? parse = converter.transformParseFromTagger(parse); if (mLogger.isLoggable(Level.INFO)) { StringBuffer parseString = new StringBuffer(); parse.show(parseString); mLogger.log(Level.INFO, parseString.toString()); } createAnnotation(cas, sentenceAnnotation.getBegin(), parse); } }
public Parse parse(Parse tokens) { if (tokens.getChildCount() > 0) { Parse p = parse(tokens,1)[0]; setParents(p); return p; } else { return tokens; } }
public Parse parse(Parse tokens) { if (tokens.getChildCount() > 0) { Parse p = parse(tokens,1)[0]; setParents(p); return p; } else { return tokens; } }
private static double numCommonSubtrees(Parse n1, Parse n2){ double retVal=1.0; if(n1.getChildCount() != n2.getChildCount()){ retVal = 0; }else if(!n1.getType().equals(n2.getType())){ retVal = 0; }else if(n1.getChildCount() == 1 && n1.getChildren()[0].getChildCount() == 0 && n2.getChildren()[0].getChildCount() == 0){ for(int i = 0; i < n1.getChildCount(); i++){ String l1 = n1.getChildren()[i].getType(); String l2 = n2.getChildren()[i].getType(); for(int i = 0; i < n1.getChildCount(); i++){ retVal *= (1 + numCommonSubtrees(n1.getChildren()[i], n2.getChildren()[i]));
private static double numCommonSubtrees(Parse n1, Parse n2){ double retVal=1.0; if(n1.getChildCount() != n2.getChildCount()){ retVal = 0; }else if(!n1.getType().equals(n2.getType())){ retVal = 0; }else if(n1.getChildCount() == 1 && n1.getChildren()[0].getChildCount() == 0 && n2.getChildren()[0].getChildCount() == 0){ for(int i = 0; i < n1.getChildCount(); i++){ String l1 = n1.getChildren()[i].getType(); String l2 = n2.getChildren()[i].getType(); for(int i = 0; i < n1.getChildCount(); i++){ retVal *= (1 + numCommonSubtrees(n1.getChildren()[i], n2.getChildren()[i]));
/** * 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()]); }
/** * 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()]); }
completeParses.clear(); int derivationStage = 0; //derivation length int maxDerivationLength = 2 * tokens.getChildCount() + 3; odh.add(tokens); Parse guess = null;
completeParses.clear(); int derivationStage = 0; //derivation length int maxDerivationLength = 2 * tokens.getChildCount() + 3; odh.add(tokens); Parse guess = null;
protected void process(CAS cas, AnnotationFS sentenceAnnotation) { FSIndex<AnnotationFS> allTokens = cas.getAnnotationIndex(mTokenType); ContainingConstraint containingConstraint = new ContainingConstraint(sentenceAnnotation); String sentence = sentenceAnnotation.getCoveredText(); Iterator<AnnotationFS> containingTokens = cas.createFilteredIterator( allTokens.iterator(), containingConstraint); List<Span> tokenSpans = new LinkedList<>(); while (containingTokens.hasNext()) { AnnotationFS token = containingTokens.next(); tokenSpans.add(new Span(token.getBegin() - sentenceAnnotation.getBegin(), token.getEnd() - sentenceAnnotation.getBegin())); } ParseConverter converter = new ParseConverter(sentence, tokenSpans.toArray(new Span[tokenSpans.size()])); Parse unparsedTree = converter.getParseForTagger(); if (unparsedTree.getChildCount() > 0) { Parse parse = mParser.parse(unparsedTree); // TODO: We need a strategy to handle the case that a full // parse could not be found. What to do in this case? parse = converter.transformParseFromTagger(parse); if (mLogger.isLoggable(Level.INFO)) { StringBuffer parseString = new StringBuffer(); parse.show(parseString); mLogger.log(Level.INFO, parseString.toString()); } createAnnotation(cas, sentenceAnnotation.getBegin(), parse); } }
public opennlp.tools.coref.mention.Parse getNextToken() { Parse parent = parse.getParent(); Parse node = parse; int index=-1; //find parent with subsequent children while(parent != null) { index = parent.indexOf(node)+1; if (index == parent.getChildCount()) { node = parent; parent = parent.getParent(); } else { break; } } //find left-most child which is a token if (parent == null) { return null; } else { Parse p = parent.getChildren()[index]; while (!p.isPosTag()) { p = p.getChildren()[0]; } return new DefaultParse(p,sentenceNumber); } }
public opennlp.tools.coref.mention.Parse getNextToken() { Parse parent = parse.getParent(); Parse node = parse; int index = -1; //find parent with subsequent children while (parent != null) { index = parent.indexOf(node) + 1; if (index == parent.getChildCount()) { node = parent; parent = parent.getParent(); } else { break; } } //find left-most child which is a token if (parent == null) { return null; } else { Parse p = parent.getChildren()[index]; while (!p.isPosTag()) { p = p.getChildren()[0]; } return new DefaultParse(p,sentenceNumber); } }
parent.setLeaf(parse.getChildCount() == 0); StringArray tags = new StringArray(jcas, typeParts.length-1); for(int i = 1; i < typeParts.length; i++){ if(subtree.getChildCount() == 1 && subtree.getChildren()[0].getChildCount() == 0){
parent.setLeaf(parse.getChildCount() == 0); StringArray tags = new StringArray(jcas, typeParts.length-1); for(int i = 1; i < typeParts.length; i++){ if(subtree.getChildCount() == 1 && subtree.getChildren()[0].getChildCount() == 0){