public virtual void PrintSentences(IEnumerable <IList <IHasWord> > sentences, string filename) { try { PrintWriter pw = IOUtils.GetPrintWriter(filename); foreach (IList <IHasWord> sentence in sentences) { pw.Print("<s> "); // Note: Use <s sentence-id > to identify sentences string sentString = SentenceUtils.ListToString(sentence); if (sentence.Count > maxSentenceLength) { logger.Warning("Sentence length=" + sentence.Count + " 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 Exception(ex); } }
public virtual string Stem(string word) { try { lexer.Yyreset(new StringReader(word)); lexer.Yybegin(Morpha.any); string wordRes = lexer.Next(); return(wordRes); } catch (IOException) { log.Warning("Morphology.stem() had error on word " + word); return(word); } }
public virtual 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.DefaultGrammarFiles; 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 static SsurgeonPattern fromXML(String xmlString) throws Exception { //SAXBuilder builder = new SAXBuilder(); //Document jdomDoc = builder.build(xmlString); //jdomDoc.getRootElement().getChildren(SsurgeonPattern.SSURGEON_ELEM_TAG); //} /// <summary>Given a target filepath and a list of Ssurgeon patterns, writes them out as XML forms.</summary> public static void WriteToFile(File tgtFile, IList <SsurgeonPattern> patterns) { try { IDocument 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(typeof(Edu.Stanford.Nlp.Semgraph.Semgrex.Ssurgeon.Ssurgeon).FullName, "writeToFile"); log.Error(e); } }