@SuppressWarnings("unchecked") public static void dumpCoreMapToStringBuilder(CoreMap cm, StringBuilder sb) { for (Class<?> rawKey : cm.keySet()) { Class<CoreAnnotation<Object>> key = (Class<CoreAnnotation<Object>>) rawKey; String className = key.getSimpleName(); Object value = cm.get(key); sb.append(className).append(": ").append(value).append("\n"); } }
/** * Copy constructor. * @param other The ArrayCoreMap to copy. It may not be null. */ @SuppressWarnings("unchecked") public ArrayCoreMap(CoreMap other) { Set<Class<?>> otherKeys = other.keySet(); size = otherKeys.size(); keys = new Class[size]; values = new Object[size]; int i = 0; for (Class key : otherKeys) { this.keys[i] = key; this.values[i] = other.get(key); i++; } }
private void cleanupTags(CoreMap cm, Map<Object, Boolean> cleaned) { cm.remove(Tags.TagsAnnotation.class); for (Class key:cm.keySet()) { Object obj = cm.get(key); if (!cleaned.containsKey(obj)) { cleaned.put(obj, false); if (obj instanceof CoreMap) { cleanupTags((CoreMap) obj, cleaned); } else if (obj instanceof Collection) { cleanupTags((Collection) obj, cleaned); } cleaned.put(obj, true); } } }
/** * Copies annotation over to this CoreMap if not already set. */ public static void copyUnsetAnnotations(CoreMap src, CoreMap dest) { for (Class key : src.keySet()) { if ( ! dest.containsKey(key)) { dest.set(key, src.get(key)); } } }
/** * Create a Sentence proto from a CoreMap instance. * This is not static, as it optionally throws an exception if the serialization is lossy. * @param sentence The CoreMap to convert. Note that it should not be a CoreLabel or an Annotation, * and should represent a sentence. * @return A protocol buffer message corresponding to this sentence * @throws IllegalArgumentException If the sentence is not a valid sentence (e.g., is a document or a word). */ public CoreNLPProtos.Sentence toProto(CoreMap sentence) { Set<Class<?>> keysToSerialize = new HashSet<>(sentence.keySet()); CoreNLPProtos.Sentence.Builder builder = toProtoBuilder(sentence, keysToSerialize); // Completeness check if (enforceLosslessSerialization && !keysToSerialize.isEmpty()) { throw new LossySerializationException("Keys are not being serialized: " + StringUtils.join(keysToSerialize)); } return builder.build(); }
/** * Returns a new CoreLabel instance based on the contents of the given * CoreMap. It copies the contents of the other CoreMap. * * @param label The CoreMap to copy */ @SuppressWarnings({"unchecked"}) public CoreLabel(CoreMap label) { super(label.size()); Consumer<Class<? extends Key<?>>> savedListener = ArrayCoreMap.listener; // don't listen to the clone operation ArrayCoreMap.listener = null; for (Class key : label.keySet()) { set(key, label.get(key)); } ArrayCoreMap.listener = savedListener; }
/** * Merge one CoreMap into another -- that is, overwrite and add any keys in * the base CoreMap with those in the one to be merged. * This method is functional -- neither of the argument CoreMaps are changed. * @param base The CoreMap to serve as the base (keys in this are lower priority) * @param toBeMerged The CoreMap to merge in (keys in this are higher priority) * @return A new CoreMap representing the merge of the two inputs */ public static CoreMap merge(CoreMap base, CoreMap toBeMerged){ //(variables) CoreMap rtn = new ArrayCoreMap(base.size()); //(copy base) for(Class key : base.keySet()){ rtn.set(key, base.get(key)); } //(merge) for(Class key : toBeMerged.keySet()){ rtn.set(key,toBeMerged.get(key)); } //(return) return rtn; }
if ( ! this.keySet().equals(other.keySet())) { return false;
CoreMap sentence = sentences.get(0); out.println("The keys of the first sentence's CoreMap are:"); out.println(sentence.keySet()); out.println(); out.println("The first sentence is:");
keySet = ((ArrayCoreMap) sentence).keySetNotNull(); } else { keySet = new IdentityHashSet<>(sentence.keySet());
private void cleanupTags(CoreMap cm, Map<Object, Boolean> cleaned) { cm.remove(Tags.TagsAnnotation.class); for (Class key:cm.keySet()) { Object obj = cm.get(key); if (!cleaned.containsKey(obj)) { cleaned.put(obj, false); if (obj instanceof CoreMap) { cleanupTags((CoreMap) obj, cleaned); } else if (obj instanceof Collection) { cleanupTags((Collection) obj, cleaned); } cleaned.put(obj, true); } } }
private void cleanupTags(CoreMap cm, Map<Object, Boolean> cleaned) { cm.remove(Tags.TagsAnnotation.class); for (Class key:cm.keySet()) { Object obj = cm.get(key); if (!cleaned.containsKey(obj)) { cleaned.put(obj, false); if (obj instanceof CoreMap) { cleanupTags((CoreMap) obj, cleaned); } else if (obj instanceof Collection) { cleanupTags((Collection) obj, cleaned); } cleaned.put(obj, true); } } }
private void cleanupTags(CoreMap cm, Map<Object, Boolean> cleaned) { cm.remove(Tags.TagsAnnotation.class); for (Class key:cm.keySet()) { Object obj = cm.get(key); if (!cleaned.containsKey(obj)) { cleaned.put(obj, false); if (obj instanceof CoreMap) { cleanupTags((CoreMap) obj, cleaned); } else if (obj instanceof Collection) { cleanupTags((Collection) obj, cleaned); } cleaned.put(obj, true); } } }
/** * Copies annotation over to this coremap if not already set */ public static void copyUnsetAnnotations(CoreMap src, CoreMap dest) { Set<Class<?>> otherKeys = src.keySet(); for (Class key : otherKeys) { if (!dest.has(key)) { dest.set(key, src.get(key)); } } }
/** * Copies annotation over to this CoreMap if not already set. */ public static void copyUnsetAnnotations(CoreMap src, CoreMap dest) { for (Class key : src.keySet()) { if ( ! dest.containsKey(key)) { dest.set(key, src.get(key)); } } }
/** * Copies annotation over to this coremap if not already set */ public static void copyUnsetAnnotations(CoreMap src, CoreMap dest) { for (Class key : src.keySet()) { if (!dest.has(key)) { dest.set(key, src.get(key)); } } }
/** * Copies annotation over to this CoreMap if not already set. */ public static void copyUnsetAnnotations(CoreMap src, CoreMap dest) { for (Class key : src.keySet()) { if ( ! dest.containsKey(key)) { dest.set(key, src.get(key)); } } }
/** * Returns a new CoreLabel instance based on the contents of the given * CoreMap. It copies the contents of the other CoreMap. * * @param label The CoreMap to copy */ @SuppressWarnings({"unchecked"}) public CoreLabel(CoreMap label) { super(label.size()); for (Class key : label.keySet()) { set(key, label.get(key)); } }
/** * Returns a new CoreLabel instance based on the contents of the given * CoreMap. It copies the contents of the other CoreMap. * * @param label The CoreMap to copy */ @SuppressWarnings({"unchecked"}) public CoreLabel(CoreMap label) { super(label.size()); Set<Class<?>> otherKeys = label.keySet(); for (Class key : otherKeys) { set(key, label.get(key)); } }