public String getMessages(Level level) { StringBuilder sb = new StringBuilder(); sb.append("\n"); LinkedHashSet<Message> theMessages = new LinkedHashSet<Message>(); theMessages.addAll(messages); final String header = "Global messages of level "+level.toString()+ " and above:"; final String headerStars = StringUtil.generateStringOfCharacter('*', 8); sb.append(headerStars).append(header).append(headerStars).append("\n"); for (Message message : theMessages) { if (level.isGreaterOrEqual(message.getLevel())) { sb.append(message.getLevel().toString()).append(" "); sb.append(message.getMessage()).append("\n"); } } sb.append(StringUtil.generateStringOfCharacter('*', headerStars.length()*2+header.length())).append("\n"); return sb.toString(); }
/** * @return A string id that, hopefully, uniquely identifies a certain subtree. This is useful, for example, for differentiating between assignments to variables, etc. * @note id is not enough, because ids are not guaranteed to be unique. */ public static <T extends Info,S extends AbstractNode<T,S>> String uniqueTreesId(List<S> parseTrees) { if (parseTrees==null) return null; List<String> ids = new ArrayList<String>(); for (S node: parseTrees) ids.add(AbstractNodeStringUtils.uniqueSubtreeId(node)); return StringUtil.join(ids, ". "); }
private String totallyOmittedString(String prefix, Set<String> words) { if (null==words) return ""; if (words.size()==0) return ""; return prefix+StringUtil.joinIterableToString(words, ", ",true)+"\n"; }
private static boolean isContentVerb(Info info) { boolean ret = false; if (isVerb(info)) { String lemma = InfoGetFields.getLemma(info); if (!StringUtil.setContainsIgnoreCase(NON_CONTENT_VERBS, lemma)) ret = true; } return ret; }
protected static Set<String> extractOnlyLemmas(Iterable<LemmaAndPos> lemmasAndPoses) { Set<String> ret = new LinkedHashSet<String>(); for (LemmaAndPos lemmaAndPos : lemmasAndPoses) { if (lemmaAndPos.getLemma().length()>0) { ret.add(lemmaAndPos.getLemma()); for (String word : StringUtil.stringToWords(lemmaAndPos.getLemma())) { ret.add(word); } } } return ret; }
List<String> wordsInLemma = StringUtil.stringToWords(lemmaToInsert); double logEstimation = 0.0; boolean foundEstimation = false; if (StringUtil.setContainsIgnoreCase(pairLemmas, lemmaToInsert))
@Override public String toShortString() { StringBuffer ret = new StringBuffer(); ret.append(StringUtil.capitalizeFirstLetterOnly(ruleBaseName)); if (extraction) ret.append(" extraction"); else ret.append(" substitution"); return ret.toString(); }
/** * HTMLize the tool tip text in order to split it into readable lines * @param toolTipText * @return */ public static String htmlizeToolTipText(String toolTipText) { if (toolTipText == null) return toolTipText; StringBuilder sb = new StringBuilder(); char[] caText = toolTipText.toCharArray(); for (int index=0;index<caText.length;index+=MAX_CHARS_PER_ROW) { int endIndex = Math.min(index+MAX_CHARS_PER_ROW, caText.length); sb.append(toolTipText.substring(index, endIndex)); if (endIndex<caText.length) { if ( Character.isLetter(caText[endIndex-1]) && Character.isLetter(caText[endIndex]) ) { sb.append(LINE_BREAK_CHAR); } sb.append('\n'); } } return "<HTML>" + StringUtil.escapeHTML(sb.toString()) + "</HTML>"; }
public SubstitutionSubtreeSpecification(String source, ExtendedNode subtreeToRemove, ExtendedNode subtreeToAdd, Set<ExtendedNode> subtreesToOmit) { super(); this.source = (source!=null)?StringUtil.capitalizeFirstLetter(source):null; this.subtreeToRemove = subtreeToRemove; this.subtreeToAdd = subtreeToAdd; this.subtreesToOmit = subtreesToOmit; }
protected void setDocumentImpl(InputStream documentStream) throws SentenceSplitterException { try { setDocument(StringUtil.convertStreamToString(documentStream)); } catch (IOException e) { throw new SentenceSplitterException("error with InputStream, see nested.",e); } }
public Map<Integer,Double> forSubstitutionMultiWord(Map<Integer,Double> originalFeatureVector, SubstituteNodeSpecificationMultiWord spec) throws TeEngineMlException { Map<Integer,Double> featureVector = new LinkedHashMap<Integer, Double>(); featureVector.putAll(originalFeatureVector); spec.addDescription("Multi-Word"); Set<String> addedHypothesisWord = new LinkedHashSet<String>(); for (String hypothesisWord : spec.getHypothesisWords()) { if (!StringUtil.setContainsIgnoreCase(spec.getTextWords(), hypothesisWord)) { addedHypothesisWord.add(hypothesisWord); } } return updateFeatureVectorForSubstitutionMultiWord(featureVector,spec,spec.getNewNodeInfo().getNamedEntityAnnotation()!=null,addedHypothesisWord); }
private Map<ExtendedNode, List<String>> buildMapForTree(TreeAndParentMap<ExtendedInfo,ExtendedNode> tree) { Map<ExtendedNode, List<String>> ret = new LinkedHashMap<ExtendedNode, List<String>>(); for (ExtendedNode node : TreeIterator.iterableTree(tree.getTree())) { String lemma = InfoGetFields.getLemma(node.getInfo()); List<String> lemmaAsList = StringUtil.stringToWords(lemma); if (lemmaAsList.size()>0) { ret.put(node, lemmaAsList); } } return ret; }
@Override public StringBuffer specString() { StringBuffer ret = new StringBuffer(); ret.append("<").append(StringUtil.capitalizeFirstLetterOnly(ruleBaseName)).append("> "); if (extraction) ret.append(" extraction"); else ret.append(" substitution"); ret.append(" rule: \""); ret.append(rule.getDescription()); ret.append("\""); if (PRINT_SENTENCE_PART_IN_RULE_SPECIFICATION) { ret.append(" The part-of-sentence (bag of words) is: \""); printLhsAsString(ret,rule.getRule().getLeftHandSide()); ret.append("\""); } return ret; }
String pos = InfoGetFields.getPartOfSpeech(missingHypothesisNode.getInfo()); String relation = InfoGetFields.getRelation(missingHypothesisNode.getInfo()); String missingHypoNodeString = StringUtil.escapeHTML(NodePrintUtilities.nodeDetailsToString(id, lemma, pos)); String parentLemma = InfoGetFields.getLemma(parent.getInfo()); String parentPos = InfoGetFields.getPartOfSpeech(parent.getInfo()); parentString = StringUtil.escapeHTML(NodePrintUtilities.nodeDetailsToString(parentId, parentLemma, parentPos));
sb.append(StringUtil.generateStringOfCharacter('-', 50)); sb.append("\n"); sb.append(TreeUtilities.treeToString(hypothesisTree)); sb.append("\n"); sb.append(StringUtil.generateStringOfCharacter('-', 50)); sb.append("\n");
public static boolean infoIsContentVerb(Info info) { boolean ret = false; if (infoHasLemma(info)) { PartOfSpeech posObject = InfoGetFields.getPartOfSpeechObject(info); if (simplerPos(posObject.getCanonicalPosTag())==SimplerCanonicalPosTag.VERB) { String lemma = InfoGetFields.getLemma(info); if (!StringUtil.setContainsIgnoreCase(NON_CONTENT_VERBS, lemma)) { if (!StringUtil.setContainsIgnoreCase(NON_CONTENT_VERBS_VERBS_ONLY, lemma)) { ret = true; } } } } return ret; }
private static String namesOfEnum(Class<? extends Enum<?>> cls) { LinkedList<String> list = new LinkedList<String>(); for (Enum<?> enumConstant : cls.getEnumConstants()) { list.add(enumConstant.name()); } return StringUtil.joinIterableToString(list, ", ",true); }
protected static Set<String> wordsInTree(ExtendedNode tree) { Set<String> ret = new LinkedHashSet<String>(); Set<ExtendedNode> setNodes = AbstractNodeUtils.treeToLinkedHashSet(tree); for (ExtendedNode node : setNodes) { if (InfoObservations.infoHasLemma(node.getInfo())) { String lemma = InfoGetFields.getLemma(node.getInfo()); ret.add(lemma); ret.addAll(StringUtil.stringToWords(lemma)); } } return ret; }
/** * @return an English sentence that is approximately equivalent to the given parse tree. * @note Currently handles only subject/object issues. */ @StandardSpecific(value = { "Stanford" }) public static <T extends Info,S extends AbstractNode<T,S>> String toEnglishSentence(S parseTree) { if (parseTree==null) throw new NullPointerException("parseTree is null"); List<String> words = new ArrayList<String> (); addWordsOfEnglishSentence(parseTree, words); String sentence = StringUtil.join(words, " "); sentence = sentence.toLowerCase(); sentence = sentence.replaceAll(" ([,.';:\\)])", "$1"); return sentence; }
public String toShortString() { StringBuffer ret = new StringBuffer(); String id = textNodeToBeSubstituted.getInfo().getId(); String lemma = InfoGetFields.getLemma(textNodeToBeSubstituted.getInfo()); String pos = InfoGetFields.getPartOfSpeech(textNodeToBeSubstituted.getInfo()); ret.append(StringUtil.capitalizeFirstLetterOnly(ruleBaseName)); ret.append(" substitute "); ret.append(NodePrintUtilities.nodeDetailsToString(id, lemma, pos)); return ret.toString(); }