/// <summary> /// Returns a new CoreLabel instance based on the contents of the given /// CoreMap. It copies the contents of the other CoreMap. /// </summary> /// <param name="label">The CoreMap to copy</param> public CoreLabel(ICoreMap label) : base(label.Size()) { foreach (var key in label.KeySet()) { Set(key, label.Get(key)); } }
/// <summary> /// Returns a new CoreLabel instance based on the contents of the given /// label. /// </summary> /// <remarks> /// Returns a new CoreLabel instance based on the contents of the given /// label. Warning: The behavior of this method is a bit disjunctive! /// If label is a CoreMap (including CoreLabel), then its entire /// contents is copied into this label. /// If label is an IndexedWord, then the backing label is copied over /// entirely. /// But, otherwise, just the /// value() and word iff it implements /// <see cref="IHasWord"/> /// is copied. /// </remarks> /// <param name="label">Basis for this label</param> public CoreLabel(ILabel label) : base(0) { if (label is ICoreMap) { ICoreMap cl = (ICoreMap)label; SetCapacity(cl.Size()); foreach (Type key in cl.KeySet()) { Set(key, cl.Get(key)); } } else { if (label is IndexedWord) { ICoreMap cl = ((IndexedWord)label).BackingLabel(); SetCapacity(cl.Size()); foreach (Type key in cl.KeySet()) { Set(key, cl.Get(key)); } } else { if (label is IHasWord) { SetWord(((IHasWord)label).Word()); } SetValue(label.Value()); } } }
// static stuff /// <summary> /// Merge one CoreMap into another -- that is, overwrite and add any keys in /// the base CoreMap with those in the one to be merged. /// </summary> /// <remarks> /// 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. /// </remarks> /// <param name="base">The CoreMap to serve as the base (keys in this are lower priority)</param> /// <param name="toBeMerged">The CoreMap to merge in (keys in this are higher priority)</param> /// <returns>A new CoreMap representing the merge of the two inputs</returns> public static ICoreMap Merge(ICoreMap @base, ICoreMap toBeMerged) { //(variables) ICoreMap rtn = new ArrayCoreMap(@base.Size()); //(copy base) foreach (Type key in @base.KeySet()) { rtn.Set(key, @base.Get(key)); } //(merge) foreach (Type key_1 in toBeMerged.KeySet()) { rtn.Set(key_1, toBeMerged.Get(key_1)); } //(return) return(rtn); }
/// <summary> /// Returns a new CoreLabel instance based on the contents of the given /// CoreMap. /// </summary> /// <remarks> /// Returns a new CoreLabel instance based on the contents of the given /// CoreMap. It copies the contents of the other CoreMap. /// </remarks> /// <param name="label">The CoreMap to copy</param> public CoreLabel(ICoreMap label) : base(label.Size()) { /* , HasContext */ // /** // * Should warnings be printed when converting from MapLabel family. // */ // private static final boolean VERBOSE = false; IConsumer <Type> savedListener = ArrayCoreMap.listener; // don't listen to the clone operation ArrayCoreMap.listener = null; foreach (Type key in label.KeySet()) { Set(key, label.Get(key)); } ArrayCoreMap.listener = savedListener; }