public virtual int Compare(T o1, T o2)
 {
     if (o1 is IComparable)
     {
         return(ErasureUtils.UncheckedCast <IComparable <T> >(o1).CompareTo(o2));
     }
     return(0);
 }
Beispiel #2
0
 /// <summary>Returns a 0-based index of the right leaf of the tree.</summary>
 /// <remarks>Returns a 0-based index of the right leaf of the tree.  Assumes the leaves had been indexed from 1</remarks>
 internal static int RightIndex(Tree tree)
 {
     if (tree.IsLeaf())
     {
         CoreLabel label = ErasureUtils.UncheckedCast(tree.Label());
         return(label.Index() - 1);
     }
     return(RightIndex(tree.Children()[tree.Children().Length - 1]));
 }
Beispiel #3
0
 /// <summary>Returns a 0-based index of the left leaf of the tree.</summary>
 /// <remarks>Returns a 0-based index of the left leaf of the tree.  Assumes the leaves had been indexed from 1</remarks>
 internal static int LeftIndex(Tree tree)
 {
     if (tree.IsLeaf())
     {
         CoreLabel label = ErasureUtils.UncheckedCast(tree.Label());
         return(label.Index() - 1);
     }
     return(LeftIndex(tree.Children()[0]));
 }
        public virtual void TestBasicRelations()
        {
            Pair <string, string>[] examples = ErasureUtils.UncheckedCast(new Pair[] { T("(NP (DNP (NP (NP (NR 浦东)) (NP (NN 开发))) (DEG 的)) (ADJP (JJ 有序)) (NP (NN 进行)))", C("nn(开发-2, 浦东-1)", "assmod(进行-5, 开发-2)", "assm(开发-2, 的-3)", "amod(进行-5, 有序-4)", "root(ROOT-0, 进行-5)"
                                                                                                                                                                            )), T("(ROOT (IP (NP (NP (NR 上海) (NR 浦东)) (NP (NN 开发) (CC 与) (NN 法制) (NN 建设))) (VP (VV 同步))))", C("nn(浦东-2, 上海-1)", "nn(建设-6, 浦东-2)", "conj(建设-6, 开发-3)", "cc(建设-6, 与-4)", "nn(建设-6, 法制-5)", "nsubj(同步-7, 建设-6)", "root(ROOT-0, 同步-7)")), T("(LCP (NP (NT 近年)) (LC 来))"
                                                                                                                                                                                                                                                                                                                                                                                                                        , C("lobj(来-2, 近年-1)", "root(ROOT-0, 来-2)")), T("(PP (P 根据) (NP (DNP (NP (NP (NN 国家)) (CC 和) (NP (NR 上海市))) (DEG 的)) (ADJP (JJ 有关)) (NP (NN 规定))))", C("root(ROOT-0, 根据-1)", "conj(上海市-4, 国家-2)", "cc(上海市-4, 和-3)", "assmod(规定-7, 上海市-4)", "assm(上海市-4, 的-5)"
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               , "amod(规定-7, 有关-6)", "pobj(根据-1, 规定-7)")), T("(IP (NP (NN 建筑)) (VP (VC 是) (NP (CP (IP (VP (VV 开发) (NP (NR 浦东)))) (DEC 的)) (QP (CD 一) (CLP (M 项))) (ADJP (JJ 主要)) (NP (NN 经济) (NN 活动)))))", C("top(是-2, 建筑-1)", "root(ROOT-0, 是-2)", "rcmod(活动-10, 开发-3)"
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             , "dobj(开发-3, 浦东-4)", "cpm(开发-3, 的-5)", "nummod(项-7, 一-6)", "clf(活动-10, 项-7)", "amod(活动-10, 主要-8)", "nn(活动-10, 经济-9)", "attr(是-2, 活动-10)")), T("(IP (NP (NN 镍)) (VP (SB 被) (VP (VV 称作) (NP (PU “) (DNP (NP (ADJP (JJ 现代)) (NP (NN 工业))) (DEG 的)) (NP (NN 维生素)) (PU ”)))))"
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            , C("nsubjpass(称作-3, 镍-1)", "pass(称作-3, 被-2)", "root(ROOT-0, 称作-3)", "amod(工业-6, 现代-5)", "assmod(维生素-8, 工业-6)", "assm(工业-6, 的-7)", "dobj(称作-3, 维生素-8)")), T("(IP (VP (VP (ADVP (AD 一)) (VP (VV 出现))) (VP (ADVP (AD 就)) (VP (SB 被) (VP (VV 纳入) (NP (NN 法制) (NN 轨道)))))))))))"
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        , C("advmod(出现-2, 一-1)", "root(ROOT-0, 出现-2)", "advmod(纳入-5, 就-3)", "pass(纳入-5, 被-4)", "dep(出现-2, 纳入-5)", "nn(轨道-7, 法制-6)", "dobj(纳入-5, 轨道-7)")), T("(IP (NP (NP (NR 格林柯尔)) (NP (NN 制冷剂)) (PRN (PU () (NP (NR 中国)) (PU ))) (ADJP (JJ 有限)) (NP (NN 公司))) (VP (VC 是) (NP (CP (CP (IP (NP (NP (NR 格林柯尔) (NN 集团) (NR 北美) (NN 公司)) (CC 与) (NP (NP (NR 中国) (NR 天津)) (NP (NN 开发区)) (ADJP (JJ 总)) (NP (NN 公司))) (CC 和) (NP (NP (NR 中国)) (NP (NR 南方)) (NP (NN 证券)) (ADJP (JJ 有限)) (NP (NN 公司)))) (VP (VV 合建))) (DEC 的))) (ADJP (JJ 合资)) (NP (NN 企业)))) (PU 。))"
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            , C("nn(公司-7, 格林柯尔-1)", "nn(公司-7, 制冷剂-2)", "prnmod(公司-7, 中国-4)", "amod(公司-7, 有限-6)", "top(是-8, 公司-7)", "root(ROOT-0, 是-8)", "nn(公司-12, 格林柯尔-9)", "nn(公司-12, 集团-10)", "nn(公司-12, 北美-11)", "conj(公司-24, 公司-12)", "cc(公司-24, 与-13)", "nn(天津-15, 中国-14)"
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                , "nn(公司-18, 天津-15)", "nn(公司-18, 开发区-16)", "amod(公司-18, 总-17)", "conj(公司-24, 公司-18)", "cc(公司-24, 和-19)", "nn(公司-24, 中国-20)", "nn(公司-24, 南方-21)", "nn(公司-24, 证券-22)", "amod(公司-24, 有限-23)", "nsubj(合建-25, 公司-24)", "rcmod(企业-28, 合建-25)", "cpm(合建-25, 的-26)"
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                , "amod(企业-28, 合资-27)", "attr(是-8, 企业-28)")), T("(IP (NP (ADJP (JJ 有关)) (NP (NN 部门))) (VP (ADVP (AD 先)) (VP (VV 送上) (NP (DP (DT 这些)) (NP (NN 法规性) (NN 文件))))) (PU 。))", C("amod(部门-2, 有关-1)", "nsubj(送上-4, 部门-2)", "advmod(送上-4, 先-3)", "root(ROOT-0, 送上-4)"
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          , "det(文件-7, 这些-5)", "nn(文件-7, 法规性-6)", "dobj(送上-4, 文件-7)")) });
            // Gloss: Shanghai Pudong de orderly advance
            // Gloss: Shanghai Pudong expand and legal-system synchronous
            // Gloss: this-year
            // Gloss: according country and Shanghai de relevant law
            // Gloss: building is expand Shanghai de primary economic activity
            // Gloss: nickel has-been named modern industry de vitamins
            // Gloss: once revealed then was included legal-system path
            // Gloss: relevant department first send these regulatory document
            // TODO(pliang): add more test cases for all the relations not covered (see WARNING below)
            // Make sure all the relations are tested for
            ICollection <string> testedRelations = new HashSet <string>();

            foreach (Pair <string, string> ex in examples)
            {
                foreach (string item in ex.second.Split("\n"))
                {
                    testedRelations.Add(Sharpen.Runtime.Substring(item, 0, item.IndexOf('(')));
                }
            }
            foreach (string relation in ChineseGrammaticalRelations.shortNameToGRel.Keys)
            {
                // TODO(pliang): don't warn for abstract relations like 'subj'
                if (!testedRelations.Contains(relation))
                {
                    System.Console.Out.WriteLine("WARNING: relation '" + relation + "' not tested");
                }
            }
            ITreeReaderFactory trf = new PennTreeReaderFactory();

            foreach (Pair <string, string> ex_1 in examples)
            {
                string testTree   = ex_1.first;
                string testAnswer = ex_1.second;
                // specifying our own TreeReaderFactory is vital so that functional
                // categories - that is -TMP and -ADV in particular - are not stripped off
                Tree tree = Tree.ValueOf(testTree, trf);
                GrammaticalStructure gs = new ChineseGrammaticalStructure(tree);
                NUnit.Framework.Assert.AreEqual("Unexpected CC processed dependencies for tree " + testTree, testAnswer, GrammaticalStructureConversionUtils.DependenciesToString(gs, gs.TypedDependenciesCCprocessed(GrammaticalStructure.Extras.Maximal), tree,
                                                                                                                                                                                  false, false, false));
            }
        }
        /// <exception cref="System.IO.IOException"/>
        /// <exception cref="System.TypeLoadException"/>
        private static Edu.Stanford.Nlp.Classify.MultinomialLogisticClassifier <LL, FF> Load <Ll, Ff>(string path)
        {
            System.Console.Error.Write("Loading classifier from " + path + "... ");
            ObjectInputStream @in = new ObjectInputStream(new FileInputStream(path));

            double[][]  myWeights      = ErasureUtils.UncheckedCast(@in.ReadObject());
            IIndex <FF> myFeatureIndex = ErasureUtils.UncheckedCast(@in.ReadObject());
            IIndex <LL> myLabelIndex   = ErasureUtils.UncheckedCast(@in.ReadObject());

            @in.Close();
            System.Console.Error.WriteLine("done.");
            return(new Edu.Stanford.Nlp.Classify.MultinomialLogisticClassifier <LL, FF>(myWeights, myFeatureIndex, myLabelIndex));
        }
Beispiel #6
0
 /**
  * This constructor allows us to use reflection for loading old class keys.
  * This is useful because we can then create distributions that do not have
  * all of the classes required for all the old keys (such as trees package classes).
  */
 private KeyLookup(String className, String oldKey) {
   //Class<?> keyClass;
     Type keyClass;
   try {
    //keyClass = Class.forName(className);
       keyClass = Type.GetType(className);
   } catch(SystemException e) {
       CoreLabel.GenericAnnotation<Object> newKey = () => typeof(Object);
     keyClass = newKey.getClass();
   }
   this.coreKey = ErasureUtils.uncheckedCast(keyClass);
   this.oldKey = oldKey;
 }
Beispiel #7
0
            /// <summary>This constructor allows us to use reflection for loading old class keys.</summary>
            /// <remarks>
            /// This constructor allows us to use reflection for loading old class keys.
            /// This is useful because we can then create distributions that do not have
            /// all of the classes required for all the old keys (such as trees package classes).
            /// </remarks>
            internal KeyLookup(string className, string oldKey)
            {
                Type keyClass;

                try
                {
                    keyClass = Sharpen.Runtime.GetType(className);
                }
                catch (TypeLoadException)
                {
                    CoreLabel.IGenericAnnotation <object> newKey = null;
                    keyClass = newKey.GetType();
                }
                this.coreKey = ErasureUtils.UncheckedCast(keyClass);
                this.oldKey  = oldKey;
            }
Beispiel #8
0
 /* this is (non-tail) recursive right now, haven't figured out a way
  * to speed it up */
 private ICollection <KeyValuePair <object, double> > EntrySet(ICollection <KeyValuePair <object, double> > s, object[] key, bool useLists)
 {
     if (depth == 1)
     {
         //System.out.println("key is long enough to add to set");
         ICollection <K> keys = map.Keys;
         foreach (K finalKey in keys)
         {
             // array doesn't escape
             K[] newKey = ErasureUtils.MkTArray <K>(typeof(object), key.Length + 1);
             if (key.Length > 0)
             {
                 System.Array.Copy(key, 0, newKey, 0, key.Length);
             }
             newKey[key.Length] = finalKey;
             MutableDouble value  = (MutableDouble)map[finalKey];
             double        value1 = value;
             if (useLists)
             {
                 s.Add(new GeneralizedCounter.Entry <object, double>(Arrays.AsList(newKey), value1));
             }
             else
             {
                 s.Add(new GeneralizedCounter.Entry <object, double>(newKey[0], value1));
             }
         }
     }
     else
     {
         ICollection <K> keys = map.Keys;
         //System.out.println("key length " + key.length);
         //System.out.println("keyset level " + depth + " " + keys);
         foreach (K o in keys)
         {
             object[] newKey = new object[key.Length + 1];
             if (key.Length > 0)
             {
                 System.Array.Copy(key, 0, newKey, 0, key.Length);
             }
             newKey[key.Length] = o;
             //System.out.println("level " + key.length + " current key " + Arrays.asList(newKey));
             ConditionalizeHelper(o).EntrySet(s, newKey, true);
         }
     }
     //System.out.println("leaving key length " + key.length);
     return(s);
 }
Beispiel #9
0
        /// <summary>
        /// A convenience method equivalent to <code>
        /// <see cref="GeneralizedCounter{K}.GetCounts(System.Collections.IList{E})"/>
        /// ({o1,o2,o3})</code>; works only for depth 3
        /// GeneralizedCounters
        /// </summary>
        public virtual double GetCount(K o1, K o2, K o3)
        {
            if (depth != 3)
            {
                WrongDepth();
            }
            GeneralizedCounter <K> gc1 = ErasureUtils.UncheckedCast <GeneralizedCounter <K> >(map[o1]);

            if (gc1 == null)
            {
                return(0.0);
            }
            else
            {
                return(gc1.GetCount(o2, o3));
            }
        }
Beispiel #10
0
 /* haven't decided about access for this one yet */
 private GeneralizedCounter <K> ConditionalizeHelper(K o)
 {
     if (depth > 1)
     {
         GeneralizedCounter <K> next = ErasureUtils.UncheckedCast(map[o]);
         if (next == null)
         {
             // adds a new GeneralizedCounter if needed
             map[o] = (next = new GeneralizedCounter <K>(depth - 1));
         }
         return(next);
     }
     else
     {
         throw new Exception("Error -- can't conditionalize a distribution of depth 1");
     }
 }
Beispiel #11
0
        /* this is (non-tail) recursive right now, haven't figured out a way
         * to speed it up */
        private ICollection <KeyValuePair <object, ClassicCounter <K> > > LowestLevelCounterEntrySet(ICollection <KeyValuePair <object, ClassicCounter <K> > > s, object[] key, bool useLists)
        {
            ICollection <K> keys = map.Keys;

            if (depth == 2)
            {
                // add these counters to set
                foreach (K finalKey in keys)
                {
                    K[] newKey = ErasureUtils.MkTArray <K>(typeof(object), key.Length + 1);
                    if (key.Length > 0)
                    {
                        System.Array.Copy(key, 0, newKey, 0, key.Length);
                    }
                    newKey[key.Length] = finalKey;
                    ClassicCounter <K> c = ConditionalizeHelper(finalKey).OneDimensionalCounterView();
                    if (useLists)
                    {
                        s.Add(new GeneralizedCounter.Entry <object, ClassicCounter <K> >(Arrays.AsList(newKey), c));
                    }
                    else
                    {
                        s.Add(new GeneralizedCounter.Entry <object, ClassicCounter <K> >(newKey[0], c));
                    }
                }
            }
            else
            {
                //System.out.println("key length " + key.length);
                //System.out.println("keyset level " + depth + " " + keys);
                foreach (K o in keys)
                {
                    object[] newKey = new object[key.Length + 1];
                    if (key.Length > 0)
                    {
                        System.Array.Copy(key, 0, newKey, 0, key.Length);
                    }
                    newKey[key.Length] = o;
                    //System.out.println("level " + key.length + " current key " + Arrays.asList(newKey));
                    ConditionalizeHelper(o).LowestLevelCounterEntrySet(s, newKey, true);
                }
            }
            //System.out.println("leaving key length " + key.length);
            return(s);
        }
Beispiel #12
0
        // static utility methods
        internal static BinaryTransition.Side GetBinarySide(Tree tree)
        {
            if (tree.Children().Length != 2)
            {
                throw new AssertionError();
            }
            CoreLabel label      = ErasureUtils.UncheckedCast(tree.Label());
            CoreLabel childLabel = ErasureUtils.UncheckedCast(tree.Children()[0].Label());

            if (label.Get(typeof(TreeCoreAnnotations.HeadWordLabelAnnotation)) == childLabel.Get(typeof(TreeCoreAnnotations.HeadWordLabelAnnotation)))
            {
                return(BinaryTransition.Side.Left);
            }
            else
            {
                return(BinaryTransition.Side.Right);
            }
        }
Beispiel #13
0
 public virtual void TestNext()
 {
     SUTime.Time anchorTime = new SUTime.IsoDate(2016, 6, 19);
     // Sunday
     Pair <SUTime.Temporal, string>[] testPairs = ErasureUtils.UncheckedCast(new Pair[] { Pair.MakePair(SUTime.Monday, "2016-06-20/2016-06-20"), Pair.MakePair(SUTime.Tuesday, "2016-06-21/2016-06-21"), Pair.MakePair(SUTime.Wednesday, "2016-06-22/2016-06-22"
                                                                                                                                                                                                                       ), Pair.MakePair(SUTime.Thursday, "2016-06-23/2016-06-23"), Pair.MakePair(SUTime.Friday, "2016-06-24/2016-06-24"), Pair.MakePair(SUTime.Saturday, "2016-06-25/2016-06-25"), Pair.MakePair(SUTime.Sunday, "2016-06-26/2016-06-26"), Pair.MakePair
                                                                                              (SUTime.Morning, "2016-06-20T06:00:00.000/2016-06-20T12:00"), Pair.MakePair(SUTime.Afternoon, "2016-06-20T12:00:00.000/PT6H"), Pair.MakePair(SUTime.Evening, "2016-06-20T18:00:00.000/PT2H"), Pair.MakePair(SUTime.Night, "2016-06-20T14:00:00.000/2016-06-21T00:00:00.000"
                                                                                                                                                                                                                                                                                                          ), Pair.MakePair(SUTime.Day, "2016-06-20/2016-06-20"), Pair.MakePair(SUTime.Week, "2016-06-20/2016-06-26"), Pair.MakePair(SUTime.Month, "2016-07-01/2016-07-31"), Pair.MakePair(SUTime.Month.MultiplyBy(3), "2016-06-19/2016-09-19"), Pair.MakePair
                                                                                              (SUTime.Quarter, "2016-07-01/2016-09-30"), Pair.MakePair(SUTime.Year, "2017-01-01/2017-12-31"), Pair.MakePair(SUTime.Winter, "2017-12-01/2017-03"), Pair.MakePair(SUTime.Spring, "2017-03-01/2017-06"), Pair.MakePair(SUTime.Summer, "2017-06-01/2017-09"
                                                                                                                                                                                                                                                                                                                    ), Pair.MakePair(SUTime.Fall, "2017-09-01/2017-12") });
     // TODO: Check this...
     // TODO: Check this...
     for (int i = 0; i < testPairs.Length; i++)
     {
         Pair <SUTime.Temporal, string> p    = testPairs[i];
         SUTime.RelativeTime            rel1 = new SUTime.RelativeTime(SUTime.TimeRef, SUTime.TemporalOp.Next, p.First());
         ResolveAndCheckRange("Next for " + p.First() + " (" + i + ')', rel1, anchorTime, p.Second());
     }
 }
 /// <summary>
 /// Returns a new empty BasicDocument with the same title, labels, and
 /// tokenizer as this Document.
 /// </summary>
 /// <remarks>
 /// Returns a new empty BasicDocument with the same title, labels, and
 /// tokenizer as this Document. This is useful when you want to make a
 /// new Document that's like the old document but
 /// can be filled with new text (e.g. if you're transforming
 /// the contents non-destructively).
 /// Subclasses that want to preserve extra state should
 /// override this method and add the extra state to the new document before
 /// returning it. The new BasicDocument is created by calling
 /// <tt>getClass().newInstance()</tt> so it should be of the correct subclass,
 /// and thus you should be able to cast it down and add extra meta data directly.
 /// Note however that in the event an Exception is thrown on instantiation
 /// (e.g. if your subclass doesn't have a public empty constructor--it should btw!)
 /// then a new <tt>BasicDocument</tt> is used instead. Thus if you want to be paranoid
 /// (or some would say "correct") you should check that your instance is of
 /// the correct sub-type as follows (this example assumes the subclass is called
 /// <tt>NumberedDocument</tt> and it has the additional <tt>number</tt>property):
 /// <pre>Document blankDocument=super.blankDocument();
 /// if(blankDocument instanceof NumberedDocument) {
 /// ((NumberedDocument)blankDocument).setNumber(getNumber());</pre>
 /// </remarks>
 public virtual IDocument <L, Word, OUT> BlankDocument <Out>()
 {
     Edu.Stanford.Nlp.Ling.BasicDocument <L> bd;
     // tries to instantiate by reflection, settles for direct instantiation
     try
     {
         bd = ErasureUtils.UncheckedCast <Edu.Stanford.Nlp.Ling.BasicDocument <L> >(System.Activator.CreateInstance(GetType()));
     }
     catch (Exception)
     {
         bd = new Edu.Stanford.Nlp.Ling.BasicDocument <L>();
     }
     // copies over basic meta-data
     bd.SetTitle(Title());
     bd.SetLabels(Labels());
     bd.SetTokenizerFactory(tokenizerFactory);
     // cast to the new output type
     return(ErasureUtils.UncheckedCast <IDocument <L, Word, OUT> >(bd));
 }
 public static void RegisterUnit(Env env, Type clazz)
 {
     FieldInfo[] fields = Sharpen.Runtime.GetDeclaredFields(clazz);
     foreach (FieldInfo field in fields)
     {
         bool isStatic = Modifier.IsStatic(field.GetModifiers());
         bool isUnit   = typeof(Unit).IsAssignableFrom(field.GetType());
         if (isStatic && isUnit)
         {
             try
             {
                 Unit unit = ErasureUtils.UncheckedCast(field.GetValue(null));
                 RegisterUnit(env, unit);
             }
             catch (MemberAccessException)
             {
             }
         }
     }
 }
Beispiel #16
0
 private void PrettyPrint(PrintWriter pw, string buffer, string bufferIncrement)
 {
     if (depth == 1)
     {
         foreach (KeyValuePair <object, double> e in EntrySet())
         {
             object key   = e.Key;
             double count = e.Value;
             pw.Println(buffer + key + "\t" + count);
         }
     }
     else
     {
         foreach (K key in TopLevelKeySet())
         {
             GeneralizedCounter <K> gc1 = Conditionalize(Arrays.AsList(ErasureUtils.UncheckedCast <K[]>(new object[] { key })));
             pw.Println(buffer + key + "\t" + gc1.TotalCount());
             gc1.PrettyPrint(pw, buffer + bufferIncrement, bufferIncrement);
         }
     }
 }
Beispiel #17
0
        public virtual string ToString(string param)
        {
            switch (param)
            {
            case "contingency":
            {
                StringBuilder sb = new StringBuilder();
                foreach (K obj in ErasureUtils.SortedIfPossible(TopLevelKeySet()))
                {
                    sb.Append(obj);
                    sb.Append(" = ");
                    GeneralizedCounter <K> gc = ConditionalizeOnce(obj);
                    sb.Append(gc);
                    sb.Append("\n");
                }
                return(sb.ToString());
            }

            case "sorted":
            {
                StringBuilder sb = new StringBuilder();
                sb.Append("{\n");
                foreach (K obj in ErasureUtils.SortedIfPossible(TopLevelKeySet()))
                {
                    sb.Append(obj);
                    sb.Append(" = ");
                    GeneralizedCounter <K> gc = ConditionalizeOnce(obj);
                    sb.Append(gc);
                    sb.Append("\n");
                }
                sb.Append("}\n");
                return(sb.ToString());
            }

            default:
            {
                return(ToString());
            }
            }
        }
Beispiel #18
0
 public virtual void TestThis()
 {
     SUTime.Time anchorTime = new SUTime.IsoDate(2016, 6, 19);
     // Sunday
     Pair <SUTime.Temporal, string>[] testPairs = ErasureUtils.UncheckedCast(new Pair[] { Pair.MakePair(SUTime.Monday, "2016-06-13/2016-06-13"), Pair.MakePair(SUTime.Tuesday, "2016-06-14/2016-06-14"), Pair.MakePair(SUTime.Wednesday, "2016-06-15/2016-06-15"
                                                                                                                                                                                                                       ), Pair.MakePair(SUTime.Thursday, "2016-06-16/2016-06-16"), Pair.MakePair(SUTime.Friday, "2016-06-17/2016-06-17"), Pair.MakePair(SUTime.Saturday, "2016-06-18/2016-06-18"), Pair.MakePair(SUTime.Sunday, "2016-06-19/2016-06-19"), Pair.MakePair
                                                                                              (SUTime.Morning, "2016-06-19T06:00:00.000/2016-06-19T12:00"), Pair.MakePair(SUTime.Afternoon, "2016-06-19T12:00:00.000/PT6H"), Pair.MakePair(SUTime.Evening, "2016-06-19T18:00:00.000/PT2H"), Pair.MakePair(SUTime.Night, "2016-06-19T14:00:00.000/2016-06-20T00:00:00.000"
                                                                                                                                                                                                                                                                                                          ), Pair.MakePair(SUTime.Day, "2016-06-19/2016-06-19"), Pair.MakePair(SUTime.Week, "2016-06-13/2016-06-19"), Pair.MakePair(SUTime.Month, "2016-06-01/2016-06-30"), Pair.MakePair(SUTime.Month.MultiplyBy(3), "2016-05-04/2016-08-03"), Pair.MakePair
                                                                                              (SUTime.Quarter, "2016-04-01/2016-06-30"), Pair.MakePair(SUTime.Year, "2016-01-01/2016-12-31"), Pair.MakePair(SUTime.Winter, "2016-12-01/2016-03"), Pair.MakePair(SUTime.Spring, "2016-03-01/2016-06"), Pair.MakePair(SUTime.Summer, "2016-06-01/2016-09"
                                                                                                                                                                                                                                                                                                                    ), Pair.MakePair(SUTime.Fall, "2016-09-01/2016-12") });
     // TODO: is this section right, should this be interpreted to be in the past?
     // TODO: Check this...
     // TODO: Check this...
     // TODO: is this right (Sunday is a weird day...)
     /*, "2016-06-01/2016-08-31"*/
     // TODO: check...
     for (int i = 0; i < testPairs.Length; i++)
     {
         Pair <SUTime.Temporal, string> p    = testPairs[i];
         SUTime.RelativeTime            rel1 = new SUTime.RelativeTime(SUTime.TimeRef, SUTime.TemporalOp.This, p.First());
         ResolveAndCheckRange("This for " + p.First() + " (" + i + ')', rel1, anchorTime, p.Second());
     }
 }
 /// <exception cref="System.IO.IOException"/>
 public static AbstractSequenceClassifier <INN> LoadClassifierFromPath <Inn>(Properties props, string path)
     where Inn : ICoreMap
 {
     //try loading as a CRFClassifier
     try
     {
         return(ErasureUtils.UncheckedCast(CRFClassifier.GetClassifier(path, props)));
     }
     catch (Exception e)
     {
         Sharpen.Runtime.PrintStackTrace(e);
     }
     //try loading as a CMMClassifier
     try
     {
         return(ErasureUtils.UncheckedCast(CMMClassifier.GetClassifier(path)));
     }
     catch (Exception e)
     {
         //fail
         //log.info("Couldn't load classifier from path :"+path);
         throw new IOException("Couldn't load classifier from " + path, e);
     }
 }
Beispiel #20
0
 public static IEquivalenceClasser <T, U> NullEquivalenceClasser <T, U>()
 {
     return(ErasureUtils.UncheckedCast <IEquivalenceClasser <T, U> >(NullEquivalenceClasser));
 }
Beispiel #21
0
 public override ICollection <KeyValuePair <K, double> > EntrySet()
 {
     return(ErasureUtils.UncheckedCast <ICollection <KeyValuePair <K, double> > >(this._enclosing._enclosing.EntrySet(new HashSet <KeyValuePair <object, double> >(), GeneralizedCounter.zeroKey, false)));
 }
Beispiel #22
0
 public override ICollection <K> KeySet()
 {
     return(ErasureUtils.UncheckedCast <ICollection <K> >(this._enclosing._enclosing.KeySet(Generics.NewHashSet(), GeneralizedCounter.zeroKey, false)));
 }
Beispiel #23
0
 /// <summary>Returns the set of entries in the GeneralizedCounter.</summary>
 /// <remarks>
 /// Returns the set of entries in the GeneralizedCounter.
 /// Here, each key is a read-only
 /// <see cref="System.Collections.IList{E}"/>
 /// of size equal to the depth of the GeneralizedCounter, and
 /// each value is a
 /// <see cref="double"/>
 /// .  Each entry is a
 /// <see cref="System.Collections.DictionaryEntry{K, V}"/>
 /// object,
 /// but these objects
 /// do not support the
 /// <see cref="System.Collections.DictionaryEntry{K, V}.SetValue(object)"/>
 /// method; attempts to call
 /// that method with result
 /// in an
 /// <see cref="System.NotSupportedException"/>
 /// being thrown.
 /// </remarks>
 public virtual ICollection <KeyValuePair <IList <K>, double> > EntrySet()
 {
     return(ErasureUtils.UncheckedCast <ICollection <KeyValuePair <IList <K>, double> > >(EntrySet(new HashSet <KeyValuePair <object, double> >(), zeroKey, true)));
 }
Beispiel #24
0
 /// <summary>
 /// Returns the set of keys, as read-only
 /// <see cref="System.Collections.IList{E}"/>
 /// s of size
 /// equal to the depth of the GeneralizedCounter.
 /// </summary>
 public virtual ICollection <IList <K> > KeySet()
 {
     return(ErasureUtils.UncheckedCast <ICollection <IList <K> > >(KeySet(Generics.NewHashSet(), zeroKey, true)));
 }
 public static IMatchCostFunction <K, V> DefaultCost <K, V>()
 {
     return(ErasureUtils.UncheckedCast(DefaultCost));
 }
Beispiel #26
0
 /// <summary>
 /// Returns a set of entries, where each key is a read-only
 /// <see cref="System.Collections.IList{E}"/>
 /// of size one less than the depth of the GeneralizedCounter, and
 /// each value is a
 /// <see cref="ClassicCounter{E}"/>
 /// .  Each entry is a
 /// <see cref="System.Collections.DictionaryEntry{K, V}"/>
 /// object, but these objects
 /// do not support the
 /// <see cref="System.Collections.DictionaryEntry{K, V}.SetValue(object)"/>
 /// method; attempts to call that method with result
 /// in an
 /// <see cref="System.NotSupportedException"/>
 /// being thrown.
 /// </summary>
 public virtual ICollection <KeyValuePair <IList <K>, ClassicCounter <K> > > LowestLevelCounterEntrySet()
 {
     return(ErasureUtils.UncheckedCast <ICollection <KeyValuePair <IList <K>, ClassicCounter <K> > > >(LowestLevelCounterEntrySet(new HashSet <KeyValuePair <object, ClassicCounter <K> > >(), zeroKey, true)));
 }
 public static IComparator <TrieMapMatcher.PartialApproxMatch <K, V> > PartialMatchComparator <K, V>()
 {
     return(ErasureUtils.UncheckedCast(PartialMatchComparator));
 }
 public virtual Type GetType()
 {
     return(ErasureUtils.UncheckedCast(typeof(IDictionary)));
 }
 public virtual Type GetType()
 {
     return(ErasureUtils.UncheckedCast(typeof(ISet)));
 }
 public virtual Type GetType()
 {
     return(ErasureUtils.UncheckedCast <Type>(typeof(IList)));
 }