public static TopTreebankNode getTreeCopy(JCas jcas, TopTreebankNode orig){ if(orig == null) return null; TopTreebankNode copy = new TopTreebankNode(jcas); copy.setNodeType(orig.getNodeType()); copy.setBegin(orig.getBegin()); copy.setEnd(orig.getEnd()); copy.setParent(null); copy.setChildren(new FSArray(jcas,1)); copy.setTreebankParse(orig.getTreebankParse()); if(orig.getChildren() == null || orig.getChildren().size() == 0){ System.err.println("WHAT?"); } copy.setChildren(0, getTreeCopy(jcas, orig.getChildren(0))); copy.getChildren(0).setParent(copy); return copy; }
/** @generated * @param jcas JCas to which this Feature Structure belongs * @param begin offset to the begin spot in the SofA * @param end offset to the end spot in the SofA */ public TopTreebankNode(JCas jcas, int begin, int end) { super(jcas); setBegin(begin); setEnd(end); readObject(); }
/** Internal - constructor used by generator * @generated * @param addr low level Feature Structure reference * @param type the type of this Feature Structure */ public TopTreebankNode(int addr, TOP_Type type) { super(addr, type); readObject(); }
/** * @param jcas ye olde ... * @param parse opennlp parse * @param terminalArray [token] terminals in the sentence * @param sentence - * @return a top treebank node for the sentence * @throws AnalysisEngineProcessException thrown by {@link #recursivelyCreateStructure} */ public static TopTreebankNode buildAlignedTree( final JCas jcas, final Parse parse, final FSArray terminalArray, final Sentence sentence ) throws AnalysisEngineProcessException { final StringBuffer parseBuffer = new StringBuffer(); if ( parse != null ) { parse.show( parseBuffer ); } final TopTreebankNode top = new TopTreebankNode( jcas, sentence.getBegin(), sentence.getEnd() ); top.setTreebankParse( parseBuffer.toString() ); top.setTerminals( terminalArray ); top.setParent( null ); if ( parse != null ) { recursivelyCreateStructure( jcas, top, parse, top ); } return top; }
public static TerminalTreebankNode getHead(TreebankNode n){ TerminalTreebankNode ttn = null; int headIndex = n.getHeadIndex(); ttn = getRoot(n).getTerminals(headIndex); return ttn; }
@Override public void process(JCas jcas) throws AnalysisEngineProcessException { String sent = jcas.getDocumentText(); StringBuffer buff = new StringBuffer(); Parse parse = null; try{ parse = ParserTool.parseLine(sent, parser, 1)[0]; parse.show(buff); }catch(NullPointerException e){ System.err.println("Parser error... no parse found... check POS tags of missed sentence (immediately above)"); } if(parse == null){ buff.append("(S null)"); } TopTreebankNode ttn = new TopTreebankNode(jcas); ttn.setTreebankParse(buff.toString()); ttn.addToIndexes(); }
@Override public void createAnnotations( final JCas jcas ) throws AnalysisEngineProcessException { final String docId = DocumentIDAnnotationUtil.getDocumentID( jcas ); logger.info( "Started processing: " + docId ); // iterate over sentences Parse parse = null; // final Collection<Sentence> allSentences = org.apache.uima.fit.util.JCasUtil.select( jcas, Sentence.class ); // for ( Sentence sentence : allSentences ) { final Map<Sentence, Collection<BaseToken>> sentenceTokenMap = JCasUtil.indexCovered( jcas, Sentence.class, BaseToken.class ); for ( Map.Entry<Sentence, Collection<BaseToken>> sentenceTokens : sentenceTokenMap.entrySet() ) { final Sentence sentence = sentenceTokens.getKey(); final String text = sentence.getCoveredText(); if ( text.isEmpty() || isBorderOnly( text ) ) { continue; } // final FSArray terminalArray = TreeUtils.getTerminals( jcas, sentence ); final FSArray terminalArray = TreeUtils.getTerminals( jcas, new ArrayList<>( sentenceTokens.getValue() ) ); final String tokenString = TreeUtils.getSplitSentence( terminalArray ); if ( tokenString.isEmpty() ) { parse = null; } else { final Parse inputTokens = TreeUtils.ctakesTokensToOpennlpTokens( sentence.getBegin(), text, terminalArray ); parse = parser.parse( inputTokens ); } final TopTreebankNode top = TreeUtils.buildAlignedTree( jcas, parse, terminalArray, sentence ); top.addToIndexes(); } logger.info( "Done parsing: " + docId ); }
ArrayList<TreebankNode> l2 = getUpwardPath(lca, t2); if(lca == null){ lca = new TopTreebankNode(jcas); lca.setNodeType("TOP"); lca.setChildren(new FSArray(jcas,2));
/** Internal - constructor used by generator * @generated * @param addr low level Feature Structure reference * @param type the type of this Feature Structure */ public TopTreebankNode(int addr, TOP_Type type) { super(addr, type); readObject(); }
/** * @param jcas ye olde ... * @param parse opennlp parse * @param terminalArray [token] terminals in the sentence * @param sentence - * @return a top treebank node for the sentence * @throws AnalysisEngineProcessException thrown by {@link #recursivelyCreateStructure} */ public static TopTreebankNode buildAlignedTree( final JCas jcas, final Parse parse, final FSArray terminalArray, final Sentence sentence ) throws AnalysisEngineProcessException { final StringBuffer parseBuffer = new StringBuffer(); if ( parse != null ) { parse.show( parseBuffer ); } final TopTreebankNode top = new TopTreebankNode( jcas, sentence.getBegin(), sentence.getEnd() ); top.setTreebankParse( parseBuffer.toString() ); top.setTerminals( terminalArray ); top.setParent( null ); if ( parse != null ) { recursivelyCreateStructure( jcas, top, parse, top ); } return top; }
public static TerminalTreebankNode getHead(TreebankNode n){ TerminalTreebankNode ttn = null; int headIndex = n.getHeadIndex(); ttn = getRoot(n).getTerminals(headIndex); return ttn; }
@Override public void process(JCas jcas) throws AnalysisEngineProcessException { String sent = jcas.getDocumentText(); StringBuffer buff = new StringBuffer(); Parse parse = null; try{ parse = ParserTool.parseLine(sent, parser, 1)[0]; parse.show(buff); }catch(NullPointerException e){ System.err.println("Parser error... no parse found... check POS tags of missed sentence (immediately above)"); } if(parse == null){ buff.append("(S null)"); } TopTreebankNode ttn = new TopTreebankNode(jcas); ttn.setTreebankParse(buff.toString()); ttn.addToIndexes(); }
@Override public void createAnnotations( final JCas jcas ) throws AnalysisEngineProcessException { final String docId = DocumentIDAnnotationUtil.getDocumentID( jcas ); logger.info( "Started processing: " + docId ); // iterate over sentences Parse parse = null; final Collection<Sentence> allSentences = org.apache.uima.fit.util.JCasUtil.select( jcas, Sentence.class ); for ( Sentence sentence : allSentences ) { final String text = sentence.getCoveredText(); if ( text.isEmpty() || isBorderOnly( text ) ) { continue; } final FSArray terminalArray = TreeUtils.getTerminals( jcas, sentence ); final String tokenString = TreeUtils.getSplitSentence( terminalArray ); if ( tokenString.isEmpty() ) { parse = null; } else { final Parse inputTokens = TreeUtils.ctakesTokensToOpennlpTokens( sentence.getBegin(), text, terminalArray ); parse = parser.parse( inputTokens ); } final TopTreebankNode top = TreeUtils.buildAlignedTree( jcas, parse, terminalArray, sentence ); top.addToIndexes(); } logger.info( "Done parsing: " + docId ); }
ArrayList<TreebankNode> l2 = getUpwardPath(lca, t2); if(lca == null){ lca = new TopTreebankNode(jcas); lca.setNodeType("TOP"); lca.setChildren(new FSArray(jcas,2));
public static TopTreebankNode getTreeCopy(JCas jcas, TopTreebankNode orig){ if(orig == null) return null; TopTreebankNode copy = new TopTreebankNode(jcas); copy.setNodeType(orig.getNodeType()); copy.setBegin(orig.getBegin()); copy.setEnd(orig.getEnd()); copy.setParent(null); copy.setChildren(new FSArray(jcas,1)); copy.setTreebankParse(orig.getTreebankParse()); if(orig.getChildren() == null || orig.getChildren().size() == 0){ System.err.println("WHAT?"); } copy.setChildren(0, getTreeCopy(jcas, orig.getChildren(0))); copy.getChildren(0).setParent(copy); return copy; }
/** @generated * @param jcas JCas to which this Feature Structure belongs * @param begin offset to the begin spot in the SofA * @param end offset to the end spot in the SofA */ public TopTreebankNode(JCas jcas, int begin, int end) { super(jcas); setBegin(begin); setEnd(end); readObject(); }
/** @generated * @param jcas JCas to which this Feature Structure belongs */ public TopTreebankNode(JCas jcas) { super(jcas); readObject(); }
public static TerminalTreebankNode getHead(TreebankNode n){ TerminalTreebankNode ttn = null; int headIndex = n.getHeadIndex(); ttn = getRoot(n).getTerminals(headIndex); return ttn; }
/** @generated * @param jcas JCas to which this Feature Structure belongs * @param begin offset to the begin spot in the SofA * @param end offset to the end spot in the SofA */ public TopTreebankNode(JCas jcas, int begin, int end) { super(jcas); setBegin(begin); setEnd(end); readObject(); }
/** @generated * @param jcas JCas to which this Feature Structure belongs */ public TopTreebankNode(JCas jcas) { super(jcas); readObject(); }