From bda41b2d3c2e1fd33733bc3862337debe3c9c119 Mon Sep 17 00:00:00 2001 From: oferbr Date: Thu, 21 Aug 2014 14:28:23 +0300 Subject: [PATCH] CasTreeConverter: enhance class. Also partially solve issue : https://github.com/hltfbk/Excitement-Open-Platform/issues/220 --- .../eop/lap/biu/uima/CasTreeConverter.java | 57 ++++--------------- 1 file changed, 11 insertions(+), 46 deletions(-) diff --git a/lap/src/main/java/eu/excitementproject/eop/lap/biu/uima/CasTreeConverter.java b/lap/src/main/java/eu/excitementproject/eop/lap/biu/uima/CasTreeConverter.java index 2f39f282..75dd4d2e 100644 --- a/lap/src/main/java/eu/excitementproject/eop/lap/biu/uima/CasTreeConverter.java +++ b/lap/src/main/java/eu/excitementproject/eop/lap/biu/uima/CasTreeConverter.java @@ -192,19 +192,9 @@ private BasicNode convertSentenceToTree(JCas jcas, Sentence sentenceAnno) throws deepDependencies = new ArrayList(); extraNodes = new LinkedHashSet(); - logger.trace(String.format("\n***************\n***************\n%s\n***************\n", sentenceAnno.getCoveredText())); - - /// DEBUG - try { - System.out.printf("\n\n\n****CasTreeConverter Input:\n\t\tSentence: %s\n\t\ttokens=%s\n\t\tdependencies=\n%s\n\n\n", - UimaUtils.annotationToString(sentenceAnno), UimaUtils.annotationCollectionToString(tokenAnnotations), - UimaUtils.annotationCollectionToString(dependencyAnnotations)); - } - catch (Exception e) { - throw new CasTreeConverterException(e); - } - //// - + logger.trace(String.format("\n***************\n***************\nCasTreeConverter Input:\n\t\tSentence: %s\n\t\ttokens=%s\n\t\tdependencies=\n%s\n***************\n", + UimaUtils.annotationToString(sentenceAnno), UimaUtils.annotationCollectionToString(tokenAnnotations), + UimaUtils.annotationCollectionToString(dependencyAnnotations))); // Get token positions in sentence (1-based) Map tokenPositions = new LinkedHashMap(tokenAnnotations.size()); @@ -212,13 +202,6 @@ private BasicNode convertSentenceToTree(JCas jcas, Sentence sentenceAnno) throws for (Token token : tokenAnnotations) { tokenPositions.put(token, i); i++; - - /// DEBUG - if (token.getCoveredText().contains("-")) { - System.out.printf("\n\n\nCasTreeConverter: Token with hyphen: '%s[%s:%s]' in sentence '%s'[%s:%s]\n\n\n", - token.getCoveredText(), token.getBegin(), token.getEnd(), sentenceAnno.getCoveredText(), sentenceAnno.getBegin(), sentenceAnno.getEnd()); - } - /// } // Create all nodes from dependents in Dependencies @@ -227,12 +210,6 @@ private BasicNode convertSentenceToTree(JCas jcas, Sentence sentenceAnno) throws Token governor = depAnno.getGovernor(); Token dependent = depAnno.getDependent(); - /// DEBUG - if (governor.getCoveredText().contains("-") || dependent.getCoveredText().contains("-")) { - System.out.printf("\n\n\nCasTreeConverter: Dependency with hyphen: gov='%s' or dep='%s', rel=%s\n\n\n", outToken(governor), outToken(dependent), depType); - } - //// - // Handle deep dependencies and antecedents if (StanfordDependenciesParserAE.getDeepDependencyRelations().contains(depType)) { deepDependencies.add(depAnno); @@ -299,21 +276,16 @@ else if (tokenToNode.containsKey(dependent)) { BasicNode root = buildNode(jcas, serialandId, serialandId, rootToken, null, null); addChildren(root, childrenByParent.get(rootToken)); - /// DEBUG + String treePrint; try { - //if (sentenceAnno.getCoveredText().contains("For us the United Natgions")) { - System.out.printf("\n\n\n****CasTreeConverter Summary:\n\t\tSentence: %s\n\t\ttokens(%s)=%s\n\t\ttree(%s nodes, out of which %s deep)=\n%s\n\n\n", - UimaUtils.annotationToString(sentenceAnno), tokenAnnotations.size(), UimaUtils.annotationCollectionToString(tokenAnnotations), - nodes.size(), extraNodes.size(), - //TreeStringGenerator.treeToStringWordPos(root) - TreeToLineString.getStringWordRelPos(root) - ); - //} - } - catch (Exception e) { - throw new CasTreeConverterException(e); + treePrint = TreeStringGenerator.treeToStringWordPos(root); + } catch (TreeStringGenerator.TreeStringGeneratorException e) { + treePrint = TreeToLineString.getStringWordRelPos(root); } - //// + + logger.trace(String.format("\n\n\n****CasTreeConverter Summary:\n\t\tSentence: %s\n\t\ttokens(%s)=%s\n\t\ttree(%s nodes, out of which %s deep)=\n%s\n\n\n", + UimaUtils.annotationToString(sentenceAnno), tokenAnnotations.size(), UimaUtils.annotationCollectionToString(tokenAnnotations), + nodes.size(), extraNodes.size(), treePrint)); if (nodes.size() != tokenAnnotations.size() + extraNodes.size()) { @@ -490,13 +462,6 @@ private BasicNode buildNode(JCas jcas, int serial, int id, Token token, String d // may be deep (if any). Note that the value collection in this MultiMap is a List. tokenToNode.put(token, node); - /// DEBUG - if (token.getCoveredText().contains("-")) { - System.out.printf("CasTreeConverter: now storing the hyphen token: %s[%s:%s]", - token.getCoveredText(), token.getBegin(), token.getEnd()); - } - /// - return node; }