public override void run(string[] args) { if (args.Length != 1) { Console.WriteLine(Help); } else { ChunkerModel model = (new ChunkerModelLoader()).load(new File(args[0])); ChunkerME chunker = new ChunkerME(model, ChunkerME.DEFAULT_BEAM_SIZE); ObjectStream <string> lineStream = new PlainTextByLineStream(new InputStreamReader(Console.OpenStandardInput)); PerformanceMonitor perfMon = new PerformanceMonitor(System.err, "sent"); perfMon.start(); try { string line; while ((line = lineStream.read()) != null) { POSSample posSample; try { posSample = POSSample.parse(line); } catch (InvalidFormatException) { Console.Error.WriteLine("Invalid format:"); Console.Error.WriteLine(line); continue; } string[] chunks = chunker.chunk(posSample.Sentence, posSample.Tags); Console.WriteLine((new ChunkSample(posSample.Sentence, posSample.Tags, chunks)).nicePrint()); perfMon.incrementCounter(); } } catch (IOException e) { CmdLineUtil.handleStdinIoError(e); } perfMon.stopAndPrintFinalResult(); } }
public override void run(string[] args) { if (args.Length != 1) { Console.WriteLine(Help); } else { POSModel model = (new POSModelLoader()).load(new File(args[0])); POSTaggerME tagger = new POSTaggerME(model); ObjectStream <string> lineStream = new PlainTextByLineStream(new InputStreamReader(Console.OpenStandardInput)); PerformanceMonitor perfMon = new PerformanceMonitor(System.err, "sent"); perfMon.start(); try { string line; while ((line = lineStream.read()) != null) { string[] whitespaceTokenizerLine = WhitespaceTokenizer.INSTANCE.tokenize(line); string[] tags = tagger.tag(whitespaceTokenizerLine); POSSample sample = new POSSample(whitespaceTokenizerLine, tags); Console.WriteLine(sample.ToString()); perfMon.incrementCounter(); } } catch (IOException e) { CmdLineUtil.handleStdinIoError(e); } perfMon.stopAndPrintFinalResult(); } }
public override void run(string[] args) { if (args.Length != 1) { Console.WriteLine(Help); } else { Detokenizer detokenizer = new DictionaryDetokenizer((new DetokenizationDictionaryLoader()).load(new File(args[0]))); ObjectStream <string> tokenizedLineStream = new PlainTextByLineStream(new InputStreamReader(Console.OpenStandardInput)); PerformanceMonitor perfMon = new PerformanceMonitor(System.err, "sent"); perfMon.start(); try { string tokenizedLine; while ((tokenizedLine = tokenizedLineStream.read()) != null) { // white space tokenize line string[] tokens = WhitespaceTokenizer.INSTANCE.tokenize(tokenizedLine); Console.WriteLine(detokenizer.detokenize(tokens, null)); perfMon.incrementCounter(); } } catch (IOException e) { CmdLineUtil.handleStdinIoError(e); } perfMon.stopAndPrintFinalResult(); } }
public override void run(string[] args) { if (args.Length == 0) { Console.WriteLine(Help); } else { NameFinderME[] nameFinders = new NameFinderME[args.Length]; for (int i = 0; i < nameFinders.Length; i++) { TokenNameFinderModel model = (new TokenNameFinderModelLoader()).load(new File(args[i])); nameFinders[i] = new NameFinderME(model); } ObjectStream <string> untokenizedLineStream = new PlainTextByLineStream(new InputStreamReader(Console.OpenStandardInput)); PerformanceMonitor perfMon = new PerformanceMonitor(System.err, "sent"); perfMon.start(); try { string line; while ((line = untokenizedLineStream.read()) != null) { string[] whitespaceTokenizerLine = WhitespaceTokenizer.INSTANCE.tokenize(line); // A new line indicates a new document, // adaptive data must be cleared for a new document if (whitespaceTokenizerLine.Length == 0) { foreach (NameFinderME nameFinder in nameFinders) { nameFinder.clearAdaptiveData(); } } IList <Span> names = new List <Span>(); foreach (TokenNameFinder nameFinder in nameFinders) { Collections.addAll(names, nameFinder.find(whitespaceTokenizerLine)); } // Simple way to drop intersecting spans, otherwise the // NameSample is invalid Span[] reducedNames = NameFinderME.dropOverlappingSpans(names.ToArray()); NameSample nameSample = new NameSample(whitespaceTokenizerLine, reducedNames, false); Console.WriteLine(nameSample.ToString()); perfMon.incrementCounter(); } } catch (IOException e) { CmdLineUtil.handleStdinIoError(e); } perfMon.stopAndPrintFinalResult(); } }
public override void run(string[] args) { if (args.Length < 1) { Console.WriteLine(Help); } else { ParserModel model = (new ParserModelLoader()).load(new File(args[args.Length - 1])); int?beamSize = CmdLineUtil.getIntParameter("-bs", args); if (beamSize == null) { beamSize = AbstractBottomUpParser.defaultBeamSize; } int? numParses = CmdLineUtil.getIntParameter("-k", args); bool showTopK; if (numParses == null) { numParses = 1; showTopK = false; } else { showTopK = true; } double?advancePercentage = CmdLineUtil.getDoubleParameter("-ap", args); if (advancePercentage == null) { advancePercentage = AbstractBottomUpParser.defaultAdvancePercentage; } opennlp.tools.parser.Parser parser = ParserFactory.create(model, beamSize.Value, advancePercentage.Value); ObjectStream <string> lineStream = new PlainTextByLineStream(new InputStreamReader(Console.OpenStandardInput)); PerformanceMonitor perfMon = new PerformanceMonitor(System.err, "sent"); perfMon.start(); try { string line; while ((line = lineStream.read()) != null) { if (line.Length == 0) { Console.WriteLine(); } else { Parse[] parses = parseLine(line, parser, numParses.Value); for (int pi = 0, pn = parses.Length; pi < pn; pi++) { if (showTopK) { Console.Write(pi + " " + parses[pi].Prob + " "); } parses[pi].show(); perfMon.incrementCounter(); } } } } catch (IOException e) { CmdLineUtil.handleStdinIoError(e); } perfMon.stopAndPrintFinalResult(); } }
public override void run(string[] args) { if (args.Length != 1) { Console.WriteLine(Help); } else { TreebankLinker treebankLinker; try { treebankLinker = new TreebankLinker(args[0], LinkerMode.TEST); } catch (IOException e) { throw new TerminateToolException(-1, "Failed to load all coreferencer models!", e); } ObjectStream <string> lineStream = new PlainTextByLineStream(new InputStreamReader(Console.OpenStandardInput)); PerformanceMonitor perfMon = new PerformanceMonitor(System.err, "parses"); perfMon.start(); try { int sentenceNumber = 0; IList <Mention> document = new List <Mention>(); IList <Parse> parses = new List <Parse>(); string line; while ((line = lineStream.read()) != null) { if (line.Equals("")) { DiscourseEntity[] entities = treebankLinker.getEntities(document.ToArray()); //showEntities(entities); (new CorefParse(this, parses, entities)).show(); sentenceNumber = 0; document.Clear(); parses.Clear(); } else { Parse p = Parse.parseParse(line); parses.Add(p); Mention[] extents = treebankLinker.MentionFinder.getMentions(new DefaultParse(p, sentenceNumber)); //construct new parses for mentions which don't have constituents. for (int ei = 0, en = extents.Length; ei < en; ei++) { //System.err.println("PennTreebankLiner.main: "+ei+" "+extents[ei]); if (extents[ei].Parse == null) { //not sure how to get head index, but its not used at this point. Parse snp = new Parse(p.Text, extents[ei].Span, "NML", 1.0, 0); p.insert(snp); extents[ei].Parse = new DefaultParse(snp, sentenceNumber); } } document.AddRange(Arrays.asList(extents)); sentenceNumber++; } perfMon.incrementCounter(); } } catch (IOException e) { CmdLineUtil.handleStdinIoError(e); } perfMon.stopAndPrintFinalResult(); } }