Ejemplo n.º 1
0
 public virtual void LoadDefaultClassifier(bool crf)
 {
     try
     {
         if (crf)
         {
             classifier = CRFClassifier.GetDefaultClassifier();
         }
         else
         {
             classifier = CMMClassifier.GetDefaultClassifier();
         }
     }
     catch (Exception e)
     {
         string message = "Error loading default " + (crf ? "CRF" : "CMM");
         string title   = (crf ? "CRF" : "CMM") + " Load Error";
         message += "\nMessage: " + e.Message;
         DisplayError(title, message);
         return;
     }
     RemoveTags();
     BuildTagPanel();
     BuildExtractButton();
 }
 /// <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);
     }
 }
        /// <exception cref="System.IO.IOException"/>
        /// <exception cref="System.TypeLoadException"/>
        /// <exception cref="System.InvalidCastException"/>
        public ClassifierCombiner(ObjectInputStream ois, Properties props)
            : base(PropertiesUtils.OverWriteProperties((Properties)ois.ReadObject(), props))
        {
            // constructor for building a ClassifierCombiner from an ObjectInputStream
            // read the initial Properties out of the ObjectInputStream so you can properly start the AbstractSequenceClassifier
            // note now we load in props from command line and overwrite any that are given for command line
            // read another copy of initProps that I have helpfully included
            // TODO: probably set initProps in AbstractSequenceClassifier to avoid this writing twice thing, its hacky
            this.initProps = PropertiesUtils.OverWriteProperties((Properties)ois.ReadObject(), props);
            // read the initLoadPaths
            this.initLoadPaths = (List <string>)ois.ReadObject();
            // read the combinationMode from the serialized version
            string cm = (string)ois.ReadObject();

            // see if there is a commandline override for the combinationMode, else set newCM to the serialized version
            ClassifierCombiner.CombinationMode newCM;
            if (props.GetProperty("ner.combinationMode") != null)
            {
                // there is a possible commandline override, have to see if its valid
                try
                {
                    // see if the commandline has a proper value
                    newCM = ClassifierCombiner.CombinationMode.ValueOf(props.GetProperty("ner.combinationMode"));
                }
                catch (ArgumentException)
                {
                    // the commandline override did not have a proper value, so just use the serialized version
                    newCM = ClassifierCombiner.CombinationMode.ValueOf(cm);
                }
            }
            else
            {
                // there was no commandline override given, so just use the serialized version
                newCM = ClassifierCombiner.CombinationMode.ValueOf(cm);
            }
            this.combinationMode = newCM;
            // read in the base classifiers
            int numClassifiers = ois.ReadInt();

            // set up the list of base classifiers
            this.baseClassifiers = new List <AbstractSequenceClassifier <IN> >();
            int i = 0;

            while (i < numClassifiers)
            {
                try
                {
                    log.Info("loading CRF...");
                    CRFClassifier <IN> newCRF = ErasureUtils.UncheckedCast(CRFClassifier.GetClassifier(ois, props));
                    baseClassifiers.Add(newCRF);
                    i++;
                }
                catch (Exception)
                {
                    try
                    {
                        log.Info("loading CMM...");
                        CMMClassifier newCMM = ErasureUtils.UncheckedCast(CMMClassifier.GetClassifier(ois, props));
                        baseClassifiers.Add(newCMM);
                        i++;
                    }
                    catch (Exception ex)
                    {
                        throw new IOException("Couldn't load classifier!", ex);
                    }
                }
            }
        }