/** * For a given Element, treats the first child as a text element * and returns its value. */ public static String getEltText(Element element) { try { NodeList childNodeList = element.getChildNodes(); if (childNodeList.getLength() == 0) return ""; return childNodeList.item(0).getNodeValue(); } catch (Exception e) { log.warning("Exception e=" + e.getMessage() + " thrown calling getEltText on element=" + element); } return ""; }
/** * Returns all of the Element typed children from the given element. Note: disregards * other node types. */ private static List<Element> getChildElements(Element element) { LinkedList<Element> childElements = new LinkedList<>(); try { NodeList nodeList = element.getChildNodes(); for (int i=0; i<nodeList.getLength(); i++) { Node node = nodeList.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { childElements.add((Element) node); } } } catch (Exception e) { log.warning("Exception thrown getting all children for element=" + element+ ", e=" + e); } return childElements; }
/** * Returns the first child whose node type is Element under the given Element. */ private static Element getFirstChildElement(Element element) { try { NodeList nodeList = element.getChildNodes(); for (int i=0; i<nodeList.getLength(); i++) { Node node = nodeList.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) return (Element) node; } } catch (Exception e) { log.warning("Error getting first child Element for element=" + element+", exception=" + e); } return null; }
logger.warning("Error interpreting number " + w + ": " + ex.getMessage()); logger.warning("NO NUMBER: " + token.word()); continue; Number num = NumberNormalizer.wordToNumber(exp); if (num == null) { logger.warning("NO NUMBER FOR: \"" + exp + "\""); logger.warning("Invalid number for: \"" + exp + "\"", ex);
logger.warning("WARNING: Only " + chunks.size() + "/" + charOffsets.size() + " chunks found. Check if offsets are sorted/nonoverlapping");
String oldLabel = token.get(CoreAnnotations.NamedEntityTagAnnotation.class); if (oldLabel != null) { logger.warning("Replacing old named entity tag " + oldLabel + " with " + label);
logger.warning("No span for " + t);
logger.warning("Error interpreting number range " + w + ": " + ex.getMessage());
logger.warning("Unexpected begin document at line (\" + filename + \",\" + lineCnt + \")");
log.warning("Morphology.stem() had error on word " + word + '/' + tag); return word;
private static Tree wordsToParse(List<String[]> sentWords) { StringBuilder sb = new StringBuilder(); for (String[] fields:sentWords) { if (sb.length() > 0) { sb.append(' '); } String str = fields[FIELD_PARSE_BIT].replace("NOPARSE", "X"); String tagword = "(" + fields[FIELD_POS_TAG] + " " + fields[FIELD_WORD] + ")"; // Replace stars int si = str.indexOf('*'); sb.append(str.substring(0, si)); sb.append(tagword); sb.append(str.substring(si+1)); si = str.indexOf('*', si+1); if (si >= 0) { logger.warning(" Parse bit with multiple *: " + str); } } String parseStr = sb.toString(); return Tree.valueOf(parseStr, treeReaderFactory); }
public static String writeToString(SsurgeonPattern pattern) { try { List<SsurgeonPattern> patterns = new LinkedList<>(); patterns.add(pattern); Document domDoc = createPatternXMLDoc(patterns); if (domDoc != null) { Transformer tformer = TransformerFactory.newInstance().newTransformer(); tformer.setOutputProperty(OutputKeys.INDENT, "yes"); StringWriter sw = new StringWriter(); tformer.transform(new DOMSource(domDoc), new StreamResult(sw)); return sw.toString(); } else { log.warning("Was not able to create XML document for pattern list."); } } catch (Exception e) { log.info("Error in writeToString, could not process pattern="+pattern); log.info(e); return null; } return ""; }
public void printSentences(Iterable<List<? extends HasWord>> sentences, String filename) { try { PrintWriter pw = IOUtils.getPrintWriter(filename); for (List<? extends HasWord> sentence:sentences) { pw.print("<s> "); // Note: Use <s sentence-id > to identify sentences String sentString = SentenceUtils.listToString(sentence); if (sentence.size() > maxSentenceLength) { logger.warning("Sentence length=" + sentence.size() + " is longer than maximum set length " + maxSentenceLength); logger.warning("Long Sentence: " + sentString); } pw.print(sentString); pw.println(" </s>"); } pw.close(); } catch (IOException ex) { throw new RuntimeException(ex); } }
/** * For the given element, finds the first child Element with the given tag. */ private static Element getFirstTag(Element element, String tag) { try { NodeList nodeList = element.getElementsByTagName(tag); if (nodeList.getLength() == 0) return null; for (int i=0; i < nodeList.getLength(); i++) { Node node = nodeList.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) return (Element) node; } } catch (Exception e) { log.warning("Error getting first tag "+tag+" under element="+element); } return null; }
/** * Given a target filepath and a list of Ssurgeon patterns, writes them out as XML forms. */ public static void writeToFile(File tgtFile, List<SsurgeonPattern> patterns) { try { Document domDoc = createPatternXMLDoc(patterns); if (domDoc != null) { Transformer tformer = TransformerFactory.newInstance().newTransformer(); tformer.setOutputProperty(OutputKeys.INDENT, "yes"); tformer.transform(new DOMSource(domDoc), new StreamResult(tgtFile)); } else { log.warning("Was not able to create XML document for pattern list, file not written."); } } catch (Exception e) { log.error(Ssurgeon.class.getName(), "writeToFile"); log.error(e); } }
/** * For the given element, returns the text for the first child Element with * the given tag. */ public static String getTagText(Element element, String tag) { try { // From root element, identify first with tag, then find the // first child under that, which we treat as a TEXT node. Element firstElt = getFirstTag(element, tag); if (firstElt == null) return ""; return getEltText(firstElt); } catch (Exception e) { log.warning("Exception thrown attempting to get tag text for tag="+tag+", from element="+element); } return ""; }
@Override public void init(Options options) { this.options = options; // NumberNormalizer.setVerbose(options.verbose); // cdm 2016: Try omitting this: Don't we want to see errors? CoreMapExpressionExtractor.setVerbose(options.verbose); if (options.grammarFilename == null) { options.grammarFilename = Options.DEFAULT_GRAMMAR_FILES; logger.warning("Time rules file is not specified: using default rules at " + options.grammarFilename); } logger.info("Using following SUTime rules: "+options.grammarFilename); timexPatterns = new GenericTimeExpressionPatterns(options); this.expressionExtractor = timexPatterns.createExtractor(); }
public String stem(String word) { try { lexer.yyreset(new StringReader(word)); lexer.yybegin(Morpha.any); String wordRes = lexer.next(); return wordRes; } catch (IOException e) { log.warning("Morphology.stem() had error on word " + word); return word; } }