<p>Part-of-speech tag a string passed in on the command line. For
example:

<p>java opennlp.tools.lang.spanish.PosTagger -test "Sr. Smith da el auto a sus hermano en Lunes."
188926
public static void main(String[] args) throws IOException {
    if (args.length == 0) {
      System.err.println("Usage: PosTaggerME [-td tagdict] model < tokenized_sentences");
      System.err.println("       PosTaggerME -test model \"sentence\"");
      System.exit(1);
    }
    int ai=0;
    boolean test = false;
    String tagdict = null;
    while(ai < args.length && args[ai].startsWith("-")) {
      if (args[ai].equals("-test")) {
        ai++;
        test=true;
      }
      else if (args[ai].equals("-td")) {
        tagdict = args[ai+1];
        ai+=2;
      }
    }
    POSTaggerME tagger;
    String modelFile = args[ai++];
    if (tagdict != null) {
      tagger = new PosTagger(modelFile, new POSDictionary(tagdict));
    }
    else {
      tagger = new PosTagger(modelFile);
    }
    if (test) {
      System.out.println(tagger.tag(args[ai]));
    }
    else {
      BufferedReader in = new BufferedReader(new InputStreamReader(System.in,"ISO-8859-1"));
      PrintStream out = new PrintStream(System.out,true,"ISO-8859-1");
      for (String line = in.readLine(); line != null; line = in.readLine()) {
        out.println(tagger.tag(line));
      }
    }
  }
47826
public void setLemmaString(String lemmaString) {
    if (!StringTools.isEmpty(lemmaString)) {
      lemma = lemmaString;
      staticLemma = true;
      postagRegexp = true;
      if (posTag != null) {
        pPosRegexMatch = Pattern.compile(posTag);
      }
    }
  }
371139
protected void inlineTag() {
        int p = bp - 1;
        try {
            nextChar();
            if (isIdentifierStart(ch)) {
                String name = readTagName();
                TagParser tp = tagParsers.get(name);

                if (tp == null) {
                    skipWhitespace();
                    inlineText(WhitespaceRetentionPolicy.REMOVE_ALL);
                    nextChar();
                } else {
                    skipWhitespace();
                    if (tp.getKind() == TagParser.Kind.INLINE) {
                        tp.parse(p);
                    } else { // handle block tags (ex: @see) in inline content
                        inlineText(WhitespaceRetentionPolicy.REMOVE_ALL); // skip content
                        nextChar();
                    }
                }
            }
        } catch (ParseException e) {
        }
    }
293292
private static String mapEnglishPennTagSetToNAF(final String postag) {
    if (postag.startsWith("RB")) {
      return "A"; // adverb
    } else if (postag.equalsIgnoreCase("CC")) {
      return "C"; // conjunction
    } else if (postag.startsWith("D") || postag.equalsIgnoreCase("PDT")) {
      return "D"; // determiner and predeterminer
    } else if (postag.startsWith("J")) {
      return "G"; // adjective
    } else if (postag.equalsIgnoreCase("NN")
        || postag.equalsIgnoreCase("NNS")) {
      return "N"; // common noun
    } else if (postag.startsWith("NNP")) {
      return "R"; // proper noun
    } else if (postag.equalsIgnoreCase("TO") || postag.equalsIgnoreCase("IN")) {
      return "P"; // preposition
    } else if (postag.startsWith("PRP") || postag.startsWith("WP")) {
      return "Q"; // pronoun
    } else if (postag.startsWith("V")) {
      return "V"; // verb
    } else {
      return "O"; // other
    }
  }
876726
protected String formatPosTag(String posTag, int position, int multiwordLength) {
    return tagFormat != null ? String.format(tagFormat, posTag) : posTag;
  }
329471
String[] tokenize(String sentence) {
    TokenizerME tokenizer = new TokenizerME(tokenModel);
    String cleanString = sentence.replace('’', '\'');  // this is the type of apostrophe that OpenNLP expects
    return tokenizer.tokenize(cleanString);
  }
464694
public String consumeTagName() {
        int start = pos;
        while (!isEmpty() && (matchesWord() || matchesAny(':', '_', '-')))
            pos++;
        
        return queue.substring(start, pos);
    }
812336
static Tag[] getInlineTags(DocImpl holder, String inlinetext) {
        ListBuffer<Tag> taglist = new ListBuffer<>();
        int delimend = 0, textstart = 0, len = inlinetext.length();
        boolean inPre = false;
        DocEnv docenv = holder.env;

        if (len == 0) {
            return taglist.toArray(new Tag[taglist.length()]);
        }
        while (true) {
            int linkstart;
            if ((linkstart = inlineTagFound(holder, inlinetext,
                                            textstart)) == -1) {
                taglist.append(new TagImpl(holder, "Text",
                                           inlinetext.substring(textstart)));
                break;
            } else {
                inPre = scanForPre(inlinetext, textstart, linkstart, inPre);
                int seetextstart = linkstart;
                for (int i = linkstart; i < inlinetext.length(); i++) {
                    char c = inlinetext.charAt(i);
                    if (Character.isWhitespace(c) ||
                        c == '}') {
                        seetextstart = i;
                        break;
                     }
                }
                String linkName = inlinetext.substring(linkstart+2, seetextstart);
                if (!(inPre && (linkName.equals("code") || linkName.equals("literal")))) {
                    //Move past the white space after the inline tag name.
                    while (Character.isWhitespace(inlinetext.
                                                      charAt(seetextstart))) {
                        if (inlinetext.length() <= seetextstart) {
                            taglist.append(new TagImpl(holder, "Text",
                                                       inlinetext.substring(textstart, seetextstart)));
                            docenv.warning(holder,
                                           "tag.Improper_Use_Of_Link_Tag",
                                           inlinetext);
                            return taglist.toArray(new Tag[taglist.length()]);
                        } else {
                            seetextstart++;
                        }
                    }
                }
                taglist.append(new TagImpl(holder, "Text",
                                           inlinetext.substring(textstart, linkstart)));
                textstart = seetextstart;   // this text is actually seetag
                if ((delimend = findInlineTagDelim(inlinetext, textstart)) == -1) {
                    //Missing closing '}' character.
                    // store the text as it is with the {@link.
                    taglist.append(new TagImpl(holder, "Text",
                                               inlinetext.substring(textstart)));
                    docenv.warning(holder,
                                   "tag.End_delimiter_missing_for_possible_SeeTag",
                                   inlinetext);
                    return taglist.toArray(new Tag[taglist.length()]);
                } else {
                    //Found closing '}' character.
                    if (linkName.equals("see")
                           || linkName.equals("link")
                           || linkName.equals("linkplain")) {
                        taglist.append( new SeeTagImpl(holder, "@" + linkName,
                              inlinetext.substring(textstart, delimend)));
                    } else {
                        taglist.append( new TagImpl(holder, "@" + linkName,
                              inlinetext.substring(textstart, delimend)));
                    }
                    textstart = delimend + 1;
                }
            }
            if (textstart == inlinetext.length()) {
                break;
            }
        }
        return taglist.toArray(new Tag[taglist.length()]);
    }
374268
public static void e(String tag, String pattern, Object... parameters) {
        e(SUBSYSTEM.MAIN, tag, pattern, parameters);
    }
420562
public String posTagging(String text){
		String ret = text;
		if (vnPosTagger != null){
			ret = vnPosTagger.tagging(text);			
		}
		
		return ret;
	}
1086138
public static void main(String[] args) throws IOException {
    if (args.length == 0) {
      System.err.println("Usage: PosTagger [-d tagdict] [-di case_insensiteve_tagdict] model < tokenized_sentences");
      System.exit(1);
    }
    int ai=0;
    boolean test = false;
    String tagdict = null;
    boolean caseSensitive = true;
    while(ai < args.length && args[ai].startsWith("-")) {
      if (args[ai].equals("-d")) {
        tagdict = args[ai+1];
        ai+=2;
      }
      else if (args[ai].equals("-di")) {
        tagdict = args[ai+1];
        ai+=2;
        caseSensitive = false;
      }
    }
    POSTaggerME tagger;
    String model = args[ai++];
    String dictFile = null;
    if (ai < args.length) {
      dictFile = args[ai++];
    }
    
    if (tagdict != null) {
      if (dictFile != null) {
        tagger = new PosTagger(model,new Dictionary(dictFile),new POSDictionary(tagdict,caseSensitive));
      }
      else {
        tagger = new PosTagger(model,new POSDictionary(tagdict,caseSensitive));
      }
    }
    else {
      if (dictFile != null) {
        tagger = new PosTagger(model,new Dictionary(dictFile));
      }
      else {
        tagger = new PosTagger(model,(Dictionary)null);
      }
    }
    if (test) {
      System.out.println(tagger.tag(args[ai]));
    }
    else {
      BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
      
      for (String line = in.readLine(); line != null; line = in.readLine()) {
        System.out.println(tagger.tag(line));
      }
    }
  }
1219548
def do_tag(self, args: argparse.Namespace):
        """"""
        # The Namespace always includes the Statement object created when parsing the command line
        statement = args.__statement__

        self.poutput("The command line you ran was: {}".format(statement.command_and_args))
        self.poutput("It generated this tag:")
        self.poutput('<{0}>{1}</{0}>'.format(args.tag, ' '.join(args.content)))
1191016
public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);

        RegularExpression<String> regex = RegularExpressionParsers.word.parse(args[0]);
        System.out.println("regex: " + regex);
        System.out.println();

        while (scan.hasNextLine()) {
            String line = scan.nextLine();

            System.out.println("contains: " + regex.apply(Arrays.asList(line.split("\\s+"))));
            System.out.println("matches:  " + regex.matches(Arrays.asList(line.split("\\s+"))));
            System.out.println();
        }

        scan.close();
    }
577212
private void establishPartOfSpeechInformation(JCas jcas) {
		logger.log(Level.FINEST, "Establishing part of speech information...");

		PartOfSpeechTagger partOfSpeechTagger = null;
		Properties settings = new Properties();
		switch (language) {
			case ARABIC:
				if(POSTagger.NO.equals(posTagger)) {
					partOfSpeechTagger = new AllLanguagesTokenizerWrapper();
					logger.log(Level.INFO, "Be aware that you use the AllLanguagesTokenizer instead of specific preprocessing for Arabic. "
							+ "Thus, tagging results might be very different (and worse).");
				} else {
					partOfSpeechTagger = new StanfordPOSTaggerWrapper();
					settings.put(PartOfSpeechTagger.STANFORDPOSTAGGER_ANNOTATE_TOKENS, true);
					settings.put(PartOfSpeechTagger.STANFORDPOSTAGGER_ANNOTATE_SENTENCES, true);
					settings.put(PartOfSpeechTagger.STANFORDPOSTAGGER_ANNOTATE_POS, true);
					settings.put(PartOfSpeechTagger.STANFORDPOSTAGGER_MODEL_PATH, Config.get(Config.STANFORDPOSTAGGER_MODEL_PATH));
					settings.put(PartOfSpeechTagger.STANFORDPOSTAGGER_CONFIG_PATH, Config.get(Config.STANFORDPOSTAGGER_CONFIG_PATH));
				}
				break;
			case VIETNAMESE:
				if(POSTagger.NO.equals(posTagger)) {
					partOfSpeechTagger = new AllLanguagesTokenizerWrapper();
					logger.log(Level.INFO, "Be aware that you use the AllLanguagesTokenizer instead of specific preprocessing for Vietnamese. "
							+ "Thus, tagging results might be very different (and worse).");
				} else {
					partOfSpeechTagger = new JVnTextProWrapper();
					settings.put(PartOfSpeechTagger.JVNTEXTPRO_ANNOTATE_TOKENS, true);
					settings.put(PartOfSpeechTagger.JVNTEXTPRO_ANNOTATE_SENTENCES, true);
					settings.put(PartOfSpeechTagger.JVNTEXTPRO_ANNOTATE_POS, true);
					settings.put(PartOfSpeechTagger.JVNTEXTPRO_WORD_MODEL_PATH, Config.get(Config.JVNTEXTPRO_WORD_MODEL_PATH));
					settings.put(PartOfSpeechTagger.JVNTEXTPRO_SENT_MODEL_PATH, Config.get(Config.JVNTEXTPRO_SENT_MODEL_PATH));
					settings.put(PartOfSpeechTagger.JVNTEXTPRO_POS_MODEL_PATH, Config.get(Config.JVNTEXTPRO_POS_MODEL_PATH));
				}
				break;
			case CROATIAN:
				if(POSTagger.NO.equals(posTagger)) {
					partOfSpeechTagger = new AllLanguagesTokenizerWrapper();
					logger.log(Level.INFO, "Be aware that you use the AllLanguagesTokenizer instead of specific preprocessing for Croatian. "
							+ "Thus, tagging results might be very different (and worse).");
				} else {
					partOfSpeechTagger = new HunPosTaggerWrapper();
					settings.put(PartOfSpeechTagger.HUNPOS_LANGUAGE, language);
					settings.put(PartOfSpeechTagger.HUNPOS_ANNOTATE_TOKENS, true);
					settings.put(PartOfSpeechTagger.HUNPOS_ANNOTATE_POS, true);
					settings.put(PartOfSpeechTagger.HUNPOS_ANNOTATE_SENTENCES, true);
					settings.put(PartOfSpeechTagger.HUNPOS_MODEL_PATH, Config.get(Config.HUNPOS_MODEL_PATH));
				}
				break;
			default:
				if(POSTagger.STANFORDPOSTAGGER.equals(posTagger)) {
					partOfSpeechTagger = new StanfordPOSTaggerWrapper();
					settings.put(PartOfSpeechTagger.STANFORDPOSTAGGER_ANNOTATE_TOKENS, true);
					settings.put(PartOfSpeechTagger.STANFORDPOSTAGGER_ANNOTATE_SENTENCES, true);
					settings.put(PartOfSpeechTagger.STANFORDPOSTAGGER_ANNOTATE_POS, true);
					settings.put(PartOfSpeechTagger.STANFORDPOSTAGGER_MODEL_PATH, Config.get(Config.STANFORDPOSTAGGER_MODEL_PATH));
					settings.put(PartOfSpeechTagger.STANFORDPOSTAGGER_CONFIG_PATH, Config.get(Config.STANFORDPOSTAGGER_CONFIG_PATH));
				} else if(POSTagger.TREETAGGER.equals(posTagger)) {
					partOfSpeechTagger = new TreeTaggerWrapper();
					settings.put(PartOfSpeechTagger.TREETAGGER_LANGUAGE, language);
					settings.put(PartOfSpeechTagger.TREETAGGER_ANNOTATE_TOKENS, true);
					settings.put(PartOfSpeechTagger.TREETAGGER_ANNOTATE_SENTENCES, true);
					settings.put(PartOfSpeechTagger.TREETAGGER_ANNOTATE_POS, true);
					settings.put(PartOfSpeechTagger.TREETAGGER_IMPROVE_GERMAN_SENTENCES, (language == Language.GERMAN));
					settings.put(PartOfSpeechTagger.TREETAGGER_CHINESE_TOKENIZER_PATH, Config.get(Config.CHINESE_TOKENIZER_PATH));
				} else if(POSTagger.HUNPOS.equals(posTagger)) {
					partOfSpeechTagger = new HunPosTaggerWrapper();
					settings.put(PartOfSpeechTagger.HUNPOS_LANGUAGE, language);
					settings.put(PartOfSpeechTagger.HUNPOS_ANNOTATE_TOKENS, true);
					settings.put(PartOfSpeechTagger.HUNPOS_ANNOTATE_POS, true);
					settings.put(PartOfSpeechTagger.HUNPOS_ANNOTATE_SENTENCES, true);
					settings.put(PartOfSpeechTagger.HUNPOS_MODEL_PATH, Config.get(Config.HUNPOS_MODEL_PATH));
				} else if(POSTagger.NO.equals(posTagger)) {
					partOfSpeechTagger = new AllLanguagesTokenizerWrapper();
					logger.log(Level.INFO, "Be aware that you use the AllLanguagesTokenizer instead of specific preprocessing for the selected language. "
							+ "If proper preprocessing for the specified language (." + language.getName() + ") is available, this might results in better "
									+ "temporal tagging quality.");
				} else {
					logger.log(Level.FINEST, "Sorry, but you can't use that tagger.");
				}
		}
		partOfSpeechTagger.initialize(settings);
		partOfSpeechTagger.process(jcas);
		partOfSpeechTagger.reset();

		logger.log(Level.FINEST, "Part of speech information established");
	}
453401
@Override
    public String[] tag(String... words)
    {
        POSInstance instance = new POSInstance(words, model.featureMap);
        return tag(instance);
    }
1069959
public static void main(String[] args) {
		if(args.length < 2){
			System.out.println("Usage: ExtractAbbreviations input experiment_name [gold-file] [train-dir] \n\n"+
					   "input - Corpus file (one line per file) from which abbreviations will be extracted.\n"+
					   "experiment_name - The experiment name will be used to create these output files:\n"+
					   "                 './<name>_abbvs' - contains the abbreviations extracted from the corpus, in a format similar to './train/abbvAlign_pairs.txt', "+
					   "the abbreviations from each document are concatenated to one line.\n"+
					   "                 './<name>_strings' - contains pairs of short and long forms of abbreviations extracted from the corpus, "+
					   "in a format that can be used for a matching experiment (using MatchExpt, AbbreviationsBlocker, and AbbreviationAlignment distance)."+
					   "train - Optional. Directory containing a corpus file named 'abbvAlign_corpus.txt' for training the abbreviation HMM. "+
					   "Corpus format is one line per file.\n"+
					   "                 The model parameters will be saved in this directory under 'hmmModelParams.txt' so the HMM will only have to be trained once.\n"+
					   "                 Default = './train/'\n"+
					   "gold - Optional. If available, the gold data will be used to estimate the performance of the HMM on the input corpus.\n"+
					   "                 './train/abbvAlign_pairs.txt' is a sample gold file for the 'train/abbvAlign_corpus.txt corpus.'\n"+
					   "                 Default = by default, no gold data is given and no estimation is done."
					   );
			System.exit(1);
		}
			
		String input = args[0];
		String output = args[1];
		
		String gold = null;
		if(args.length > 2)
			gold = args[2];
		
		String train = "./train";
		if(args.length > 3)
			train = args[3];
		
		ExtractAbbreviations tester = new ExtractAbbreviations(input, output, train, gold);
		try {
			tester.run();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
180353
public String tag(ImapRequestLineReader request) throws ProtocolException {
        CharacterValidator validator = new TagCharValidator();
        return consumeWord(request, validator);
    }