/** * Specify the String and the int identifying which word shaper to * use and this returns the result of using that wordshaper on the String. * * @param inStr String to calculate word shape of * @param wordShaper Constant for which shaping formula to use * @return The wordshape String */ public static String wordShape(String inStr, int wordShaper) { return wordShape(inStr, wordShaper, null); }
public String distSimClass(String word) { if ( ! cased) { word = word.toLowerCase(); } if (numberEquivalence) { word = WordShapeClassifier.wordShape(word, WordShapeClassifier.WORDSHAPEDIGITS); } String distSim = lexicon.get(word); if (distSim == null) { distSim = unknownWordClass; } return distSim; }
@Override String extract(History h, PairsHolder pH) { StringBuilder sb = new StringBuilder(); for (int j = left; j <= right; j++) { String s = pH.getWord(h, j); sb.append(WordShapeClassifier.wordShape(s, wordShaper)); if (j < right) { sb.append('|'); } } return sb.toString(); }
@Override String extract(History h, PairsHolder pH) { String s = super.extract(h, pH); String shape = WordShapeClassifier.wordShape(s, wordShaper); return shape; }
public String wordShape(String word){ String wordShape = constVars.getWordShapeCache().get(word); if(wordShape == null){ wordShape = WordShapeClassifier.wordShape(word, constVars.wordShaper); constVars.getWordShapeCache().put(word, wordShape); } return wordShape; }
public void addWordShapes(String label, Set<CandidatePhrase> words){ if(!this.wordShapesForLabels.containsKey(label)){ this.wordShapesForLabels.put(label, new ClassicCounter<>()); } for(CandidatePhrase wc: words){ String w = wc.getPhrase(); String ws = null; if(wordShapeCache.containsKey(w)) ws = wordShapeCache.get(w); else{ ws = WordShapeClassifier.wordShape(w, wordShaper); wordShapeCache.put(w, ws); } wordShapesForLabels.get(label).incrementCount(ws); } }
/** * Usage: {@code java edu.stanford.nlp.process.WordShapeClassifier * [-wordShape name] string+ }<br> * where {@code name} is an argument to {@code lookupShaper}. * Known names have patterns along the lines of: dan[12](bio)?(UseLC)?, * jenny1(useLC)?, chris[1234](useLC)?, cluster1. * If you don't specify a word shape function, you get chris1. * * @param args Command-line arguments, as above. */ public static void main(String[] args) { int i = 0; int classifierToUse = WORDSHAPECHRIS1; if (args.length == 0) { System.out.println("edu.stanford.nlp.process.WordShapeClassifier [-wordShape name] string+"); } else if (args[0].charAt(0) == '-') { if (args[0].equals("-wordShape") && args.length >= 2) { classifierToUse = lookupShaper(args[1]); i += 2; } else { log.info("Unknown flag: " + args[0]); i++; } } for (; i < args.length; i++) { System.out.print(args[i] + ": "); System.out.println(wordShape(args[i], classifierToUse)); } }
private void distSimAnnotate(PaddedList<IN> info) { for (CoreLabel fl : info) { if (fl.containsKey(CoreAnnotations.DistSimAnnotation.class)) { return; } String word = getWord(fl); if ( ! flags.casedDistSim) { word = word.toLowerCase(); } if (flags.numberEquivalenceDistSim) { word = WordShapeClassifier.wordShape(word, WordShapeClassifier.WORDSHAPEDIGITS); } String distSim = lexicon.get(word); if (distSim == null) { distSim = flags.unknownWordDistSimClass; } fl.set(CoreAnnotations.DistSimAnnotation.class, distSim); } }
word = WordShapeClassifier.wordShape(word, WordShapeClassifier.WORDSHAPEDIGITS);
word = WordShapeClassifier.wordShape(word, WordShapeClassifier.WORDSHAPEDIGITS);
String s = intern(WordShapeClassifier.wordShape(word, flags.wordShape, knownLCWords)); fl.set(CoreAnnotations.ShapeAnnotation.class, s);
/** * Specify the String and the int identifying which word shaper to * use and this returns the result of using that wordshaper on the String. * * @param inStr String to calculate word shape of * @param wordShaper Constant for which shaping formula to use * @return The wordshape String */ public static String wordShape(String inStr, int wordShaper) { return wordShape(inStr, wordShaper, null); }
/** * Specify the String and the int identifying which word shaper to * use and this returns the result of using that wordshaper on the String. * * @param inStr String to calculate word shape of * @param wordShaper Constant for which shaping formula to use * @return The wordshape String */ public static String wordShape(String inStr, int wordShaper) { return wordShape(inStr, wordShaper, null); }
@Override String extract(History h, PairsHolder pH) { String s = super.extract(h, pH); String shape = WordShapeClassifier.wordShape(s, wordShaper); return shape; }
@Override String extract(History h, PairsHolder pH) { StringBuilder sb = new StringBuilder(); for (int j = left; j <= right; j++) { String s = pH.getWord(h, j); sb.append(WordShapeClassifier.wordShape(s, wordShaper)); if (j < right) { sb.append('|'); } } return sb.toString(); }
@Override String extract(History h, PairsHolder pH) { StringBuilder sb = new StringBuilder(); for (int j = left; j <= right; j++) { String s = pH.getWord(h, j); sb.append(WordShapeClassifier.wordShape(s, wordShaper)); if (j < right) { sb.append('|'); } } return sb.toString(); }
@Override String extract(History h, PairsHolder pH) { String s = super.extract(h, pH); String shape = WordShapeClassifier.wordShape(s, wordShaper); return shape; }
@Override String extract(History h, PairsHolder pH) { StringBuilder sb = new StringBuilder(); for (int j = left; j <= right; j++) { String s = pH.getWord(h, j); sb.append(WordShapeClassifier.wordShape(s, wordShaper)); if (j < right) { sb.append('|'); } } return sb.toString(); }
public String wordShape(String word){ String wordShape = constVars.getWordShapeCache().get(word); if(wordShape == null){ wordShape = WordShapeClassifier.wordShape(word, constVars.wordShaper); constVars.getWordShapeCache().put(word, wordShape); } return wordShape; }