Example #1
0
            public override bool Equals(object o)
            {
                if (this == o)
                {
                    return(true);
                }
                if (!(o is GeneralizedCounter.Entry))
                {
                    return(false);
                }
                GeneralizedCounter.Entry <K, V> e = ErasureUtils.UncheckedCast <GeneralizedCounter.Entry <K, V> >(o);
                object key1 = e.Key;

                if (!(key != null && key.Equals(key1)))
                {
                    return(false);
                }
                object value1 = e.Value;

                if (!(value != null && value.Equals(value1)))
                {
                    return(false);
                }
                return(true);
            }
        // end enum Output style
        // = null;
        public virtual void Init(SeqClassifierFlags flags)
        {
            string options = "tokenizeNLs=false,invertible=true";

            if (flags.tokenizerOptions != null)
            {
                options = options + ',' + flags.tokenizerOptions;
            }
            ITokenizerFactory <In> factory;

            if (flags.tokenizerFactory != null)
            {
                try
                {
                    Type       clazz         = ErasureUtils.UncheckedCast(Sharpen.Runtime.GetType(flags.tokenizerFactory));
                    MethodInfo factoryMethod = clazz.GetMethod("newCoreLabelTokenizerFactory", typeof(string));
                    factory = ErasureUtils.UncheckedCast(factoryMethod.Invoke(null, options));
                }
                catch (Exception e)
                {
                    throw new Exception(e);
                }
            }
            else
            {
                factory = ErasureUtils.UncheckedCast(PTBTokenizer.PTBTokenizerFactory.NewCoreLabelTokenizerFactory(options));
            }
            Init(flags, factory);
        }
        public virtual void AddTag(string tag, IValue v)
        {
            if (tags == null)
            {
                tags = new Dictionary <string, IValue>(1);
            }
            //Generics.newHashMap(1);
            // Adds v as a tag into a list of tags...
            IList <IValue> tagList = null;

            if (tags.Contains(tag))
            {
                IValue oldValue = tags[tag];
                if (Expressions.TypeList.Equals(oldValue.GetType()))
                {
                    tagList = ErasureUtils.UncheckedCast(oldValue.Get());
                }
                else
                {
                    // Put the oldValue into a new array
                    tagList = new List <IValue>();
                    tagList.Add(oldValue);
                    tags[tag] = Expressions.CreateValue(Expressions.TypeList, tagList);
                }
            }
            else
            {
                tagList   = new List <IValue>();
                tags[tag] = Expressions.CreateValue(Expressions.TypeList, tagList);
            }
            tagList.Add(v);
        }
Example #4
0
        /// <exception cref="System.IO.IOException"/>
        /// <exception cref="System.TypeLoadException"/>
        private static void DemonstrateSerialization()
        {
            System.Console.Out.WriteLine();
            System.Console.Out.WriteLine("Demonstrating working with a serialized classifier");
            ColumnDataClassifier         cdc = new ColumnDataClassifier(where + "examples/cheese2007.prop");
            IClassifier <string, string> cl  = cdc.MakeClassifier(cdc.ReadTrainingExamples(where + "examples/cheeseDisease.train"));

            // Exhibit serialization and deserialization working. Serialized to bytes in memory for simplicity
            System.Console.Out.WriteLine();
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            ObjectOutputStream    oos  = new ObjectOutputStream(baos);

            oos.WriteObject(cl);
            oos.Close();
            byte[] @object                       = baos.ToByteArray();
            ByteArrayInputStream bais            = new ByteArrayInputStream(@object);
            ObjectInputStream    ois             = new ObjectInputStream(bais);
            LinearClassifier <string, string> lc = ErasureUtils.UncheckedCast(ois.ReadObject());

            ois.Close();
            ColumnDataClassifier cdc2 = new ColumnDataClassifier(where + "examples/cheese2007.prop");

            // We compare the output of the deserialized classifier lc versus the original one cl
            // For both we use a ColumnDataClassifier to convert text lines to examples
            System.Console.Out.WriteLine();
            System.Console.Out.WriteLine("Making predictions with both classifiers");
            foreach (string line in ObjectBank.GetLineIterator(where + "examples/cheeseDisease.test", "utf-8"))
            {
                IDatum <string, string> d  = cdc.MakeDatumFromLine(line);
                IDatum <string, string> d2 = cdc2.MakeDatumFromLine(line);
                System.Console.Out.Printf("%s  =origi=>  %s (%.4f)%n", line, cl.ClassOf(d), cl.ScoresOf(d).GetCount(cl.ClassOf(d)));
                System.Console.Out.Printf("%s  =deser=>  %s (%.4f)%n", line, lc.ClassOf(d2), lc.ScoresOf(d).GetCount(lc.ClassOf(d)));
            }
        }
Example #5
0
        /// <summary>Returns a 0-based index of the head of the tree.</summary>
        /// <remarks>Returns a 0-based index of the head of the tree.  Assumes the leaves had been indexed from 1</remarks>
        internal static int HeadIndex(Tree tree)
        {
            CoreLabel label     = ErasureUtils.UncheckedCast(tree.Label());
            CoreLabel headLabel = label.Get(typeof(TreeCoreAnnotations.HeadWordLabelAnnotation));

            return(headLabel.Index() - 1);
        }
        /// <summary>Loads the model from disk.</summary>
        /// <param name="path">The location of model that was saved to disk</param>
        /// <exception cref="System.InvalidCastException">if model is the wrong format</exception>
        /// <exception cref="System.IO.IOException">
        /// if the model file doesn't exist or is otherwise
        /// unavailable/incomplete
        /// </exception>
        /// <exception cref="System.TypeLoadException">this would probably indicate a serious classpath problem</exception>
        public static Edu.Stanford.Nlp.IE.Machinereading.BasicEntityExtractor Load(string path, Type entityClassifier, bool preferDefaultGazetteer)
        {
            // load the additional arguments
            // try to load the extra file from the CLASSPATH first
            InputStream @is = typeof(Edu.Stanford.Nlp.IE.Machinereading.BasicEntityExtractor).GetClassLoader().GetResourceAsStream(path + ".extra");

            // if not found in the CLASSPATH, load from the file system
            if (@is == null)
            {
                @is = new FileInputStream(path + ".extra");
            }
            ObjectInputStream @in = new ObjectInputStream(@is);
            string            gazetteerLocation = ErasureUtils.UncheckedCast <string>(@in.ReadObject());

            if (preferDefaultGazetteer)
            {
                gazetteerLocation = DefaultPaths.DefaultNflGazetteer;
            }
            ICollection <string> annotationsToSkip = ErasureUtils.UncheckedCast <ICollection <string> >(@in.ReadObject());
            bool useSubTypes = ErasureUtils.UncheckedCast <bool>(@in.ReadObject());
            bool useBIO      = ErasureUtils.UncheckedCast <bool>(@in.ReadObject());

            @in.Close();
            @is.Close();
            Edu.Stanford.Nlp.IE.Machinereading.BasicEntityExtractor extractor = (Edu.Stanford.Nlp.IE.Machinereading.BasicEntityExtractor)MachineReading.MakeEntityExtractor(entityClassifier, gazetteerLocation);
            // load the CRF classifier (this works from any resource, e.g., classpath or file system)
            extractor.classifier = CRFClassifier.GetClassifier(path);
            // copy the extra arguments
            extractor.annotationsToSkip = annotationsToSkip;
            extractor.useSubTypes       = useSubTypes;
            extractor.useBIO            = useBIO;
            return(extractor);
        }
Example #7
0
 public static IList <Tree> ConvertToTrees(byte[] input)
 {
     try
     {
         IList <Tree>         output = new List <Tree>();
         ByteArrayInputStream bis    = new ByteArrayInputStream(input);
         GZIPInputStream      gis    = new GZIPInputStream(bis);
         ObjectInputStream    ois    = new ObjectInputStream(gis);
         int size = ErasureUtils.UncheckedCast <int>(ois.ReadObject());
         for (int i = 0; i < size; ++i)
         {
             string rawTree = ErasureUtils.UncheckedCast(ois.ReadObject());
             Tree   tree    = Tree.ValueOf(rawTree, trf);
             tree.SetSpans();
             output.Add(tree);
         }
         ois.Close();
         gis.Close();
         bis.Close();
         return(output);
     }
     catch (IOException e)
     {
         throw new RuntimeIOException(e);
     }
     catch (TypeLoadException e)
     {
         throw new Exception(e);
     }
 }
 public virtual int Compare(T o1, T o2)
 {
     if (o1 is IComparable)
     {
         return(ErasureUtils.UncheckedCast <IComparable <T> >(o1).CompareTo(o2));
     }
     return(0);
 }
Example #9
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]));
 }
Example #10
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]));
 }
        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));
        }
Example #13
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;
            }
Example #14
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");
     }
 }
Example #15
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));
            }
        }
Example #16
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);
            }
        }
 /// <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));
 }
Example #18
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());
     }
 }
 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)
             {
             }
         }
     }
 }
Example #20
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);
         }
     }
 }
Example #21
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);
     }
 }
 public virtual Type GetType()
 {
     return(ErasureUtils.UncheckedCast(typeof(ISet)));
 }
Example #24
0
 public static IEquivalenceClasser <T, U> NullEquivalenceClasser <T, U>()
 {
     return(ErasureUtils.UncheckedCast <IEquivalenceClasser <T, U> >(NullEquivalenceClasser));
 }
 public virtual Type GetType()
 {
     return(ErasureUtils.UncheckedCast(typeof(IDictionary)));
 }
Example #26
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)));
 }
Example #27
0
 public override ICollection <K> KeySet()
 {
     return(ErasureUtils.UncheckedCast <ICollection <K> >(this._enclosing._enclosing.KeySet(Generics.NewHashSet(), GeneralizedCounter.zeroKey, false)));
 }
Example #28
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)));
 }
Example #29
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)));
 }
Example #30
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)));
 }