/** * Assigns parent references for the specified parse so that they * are consistent with the children references. * @param p The parse whose parent references need to be assigned. */ public static void setParents(Parse p) { Parse[] children = p.getChildren(); for (int ci = 0; ci < children.length; ci++) { children[ci].setParent(p); setParents(children[ci]); } }
/** * Returns true if the specified child is the last child of the specified parent. * @param child The child parse. * @param parent The parent parse. * @return true if the specified child is the last child of the specified parent; false otherwise. */ protected boolean lastChild(Parse child, Parse parent) { Parse[] kids = AbstractBottomUpParser.collapsePunctuation(parent.getChildren(),punctSet); return kids[kids.length - 1] == child; }
public Parse parse(Parse tokens) { if (tokens.getChildCount() > 0) { Parse p = parse(tokens,1)[0]; setParents(p); return p; } else { return tokens; } }
public ParserModel updateCheckModel(MaxentModel checkModel) { return new ParserModel(getLanguage(), getBuildModel(), checkModel, getAttachModel(), getParserTaggerModel(), getParserChunkerModel(), getHeadRules(), getParserType()); }
public ParserModel updateBuildModel(MaxentModel buildModel) { return new ParserModel(getLanguage(), buildModel, getCheckModel(), getAttachModel(), getParserTaggerModel(), getParserChunkerModel(), getHeadRules(), getParserType()); }
public ParserModel updateChunkerModel(ChunkerModel chunkModel) { return new ParserModel(getLanguage(), getBuildModel(), getCheckModel(), getAttachModel(), getParserTaggerModel(), chunkModel, getHeadRules(), getParserType()); }
public ParserModel updateTaggerModel(POSModel taggerModel) { return new ParserModel(getLanguage(), getBuildModel(), getCheckModel(), getAttachModel(), taggerModel, getParserChunkerModel(), getHeadRules(), getParserType()); }
public void add(Parse daughter, HeadRules rules) { if (daughter.prevPunctSet != null) { parts.addAll(daughter.prevPunctSet); } parts.add(daughter); this.span = new Span(span.getStart(),daughter.getSpan().getEnd()); this.head = rules.getHead(getChildren(),type); this.headIndex = head.headIndex; }
@Override protected Parse[] advanceChunks(Parse p, double minChunkScore) { Parse[] parses = super.advanceChunks(p, minChunkScore); for (Parse parse : parses) { Parse[] chunks = parse.getChildren(); for (int ci = 0; ci < chunks.length; ci++) { setComplete(chunks[ci]); } } return parses; }
@Override protected ParserModel loadModel(InputStream modelIn) throws IOException, InvalidFormatException { return new ParserModel(modelIn); }
public static Parser create(ParserModel model) { return create(model, AbstractBottomUpParser.defaultBeamSize, AbstractBottomUpParser.defaultAdvancePercentage); } }
public AbstractParserEventStream(ObjectStream<Parse> d, HeadRules rules, ParserEventTypeEnum etype, Dictionary dict) { super(d); this.dict = dict; if (etype == ParserEventTypeEnum.CHUNK) { this.chunkerContextGenerator = new ChunkContextGenerator(); } else if (etype == ParserEventTypeEnum.TAG) { this.tagContextGenerator = new DefaultPOSContextGenerator(null); } this.rules = rules; punctSet = rules.getPunctuationTags(); this.etype = etype; init(); }
/** * Parses the specified tree-bank style parse string and return a Parse structure for that string. * * @param parse A tree-bank style parse string. * * @return a Parse structure for the specified tree-bank style parse string. */ public static Parse parseParse(String parse) { return parseParse(parse,null); }
public ParserType getParserType() { return ParserType.parse(getManifestProperty(PARSER_TYPE)); }
@Override protected void advanceTop(Parse p) { p.setType(TOP_NODE); }
/** * Represents this parse in a human readable way. */ @Override public String toString() { // TODO: Use the commented code in next bigger release, // change probably breaks backward compatibility in some // applications //StringBuffer buffer = new StringBuffer(); //show(buffer); //return buffer.toString(); return getCoveredText(); }
/** * Prints to standard out a representation of the specified parse which * contains hash codes so that parent/child relationships can be explicitly seen. */ public void showCodeTree() { codeTree(this,new int[0]); }
@Override public ChunkerContextGenerator getContextGenerator() { return new ChunkContextGenerator(ChunkerME.DEFAULT_BEAM_SIZE); }
private static boolean lastChild(Parse child, Parse parent, Set<String> punctSet) { if (parent == null) { return false; } Parse[] kids = collapsePunctuation(parent.getChildren(), punctSet); return (kids[kids.length - 1] == child); }
/** * Returns true if the specified child is the first child of the specified parent. * @param child The child parse. * @param parent The parent parse. * @return true if the specified child is the first child of the specified parent; false otherwise. */ protected boolean firstChild(Parse child, Parse parent) { return AbstractBottomUpParser.collapsePunctuation(parent.getChildren(), punctSet)[0] == child; }