// get signs using an additional arg for a target rel private Collection<Sign> getSignsFromPredAndTargetRel(String pred, String targetRel) { Collection<Word> words = (Collection<Word>) _predToWords.get(pred); String specialTokenConst = null; // for robustness, when using supertagger, add words for pred sans sense index int dotIndex = -1; if (_supertagger != null && !Character.isDigit(pred.charAt(0)) && // skip numbers (dotIndex = pred.lastIndexOf('.')) > 0 && pred.length() > dotIndex + 1 && pred.charAt(dotIndex + 1) != '_') // skip titles, eg Mr._Smith { String barePred = pred.substring(0, dotIndex); Collection<Word> barePredWords = (Collection<Word>) _predToWords.get(barePred); if (words == null) words = barePredWords; else if (barePredWords != null) { Set<Word> unionWords = new HashSet<Word>(words); unionWords.addAll(barePredWords); words = unionWords; } } if (words == null) { specialTokenConst = tokenizer.getSpecialTokenConstant(tokenizer.isSpecialToken(pred)); if (specialTokenConst == null) return null; // lookup words with pred = special token const Collection<Word> specialTokenWords = (Collection<Word>) _predToWords.get(specialTokenConst); // replace special token const with pred if (specialTokenWords == null) return null; words = new ArrayList<Word>(specialTokenWords.size()); for (Iterator<Word> it = specialTokenWords.iterator(); it.hasNext(); ) { Word stw = it.next(); Word w = Word.createSurfaceWord(stw, pred); words.add(w); } } List<Sign> retval = new ArrayList<Sign>(); for (Iterator<Word> it = words.iterator(); it.hasNext(); ) { Word w = it.next(); try { SignHash signs = getSignsFromWord(w, specialTokenConst, pred, targetRel); retval.addAll(signs.asSignSet()); } // shouldn't happen catch (LexException exc) { System.err.println("Unexpected lex exception for word " + w + ": " + exc); } } return retval; }
/** {@inheritDoc} */ @SuppressWarnings({"SuspiciousMethodCalls"}) public boolean retainAll(Collection<?> collection) { boolean modified = false; TCharIterator iter = iterator(); while (iter.hasNext()) { if (!collection.contains(Character.valueOf(iter.next()))) { iter.remove(); modified = true; } } return modified; }
/** {@inheritDoc} */ @Override public boolean retainAll(Collection<?> collection) { boolean modified = false; TCharIterator iter = iterator(); while (iter.hasNext()) { if (!collection.contains(Character.valueOf(iter.next()))) { iter.remove(); modified = true; } } return modified; }
@SuppressWarnings("UnnecessaryBoxing") private static Object box(final Object value) { Object newBoxedValue; if (value instanceof Integer) { newBoxedValue = Integer.valueOf(((Integer) value).intValue()); } else if (value instanceof Byte) { newBoxedValue = Byte.valueOf(((Byte) value).byteValue()); } else if (value instanceof Short) { newBoxedValue = Short.valueOf(((Short) value).shortValue()); } else if (value instanceof Long) { newBoxedValue = Long.valueOf(((Long) value).longValue()); } else if (value instanceof Boolean) { newBoxedValue = Boolean.valueOf(((Boolean) value).booleanValue()); } else if (value instanceof Character) { newBoxedValue = Character.valueOf(((Character) value).charValue()); } else { return new Object(); } return newBoxedValue; }