Beispiel #1
0
 /// <exception cref="System.IO.IOException"/>
 public NERClassifierCombiner(bool applyNumericClassifiers, NERClassifierCombiner.Language nerLanguage, bool useSUTime, bool augmentRegexNER, Properties nscProps, params string[] loadPaths)
     : base(nscProps, ClassifierCombiner.ExtractCombinationModeSafe(nscProps), loadPaths)
 {
     // NOTE: nscProps may contains sutime props which will not be recognized by the SeqClassifierFlags
     this.applyNumericClassifiers = applyNumericClassifiers;
     this.nerLanguage             = nerLanguage;
     this.useSUTime = useSUTime;
     // check for which language to use for number sequence classifier
     if (nerLanguage == NERClassifierCombiner.Language.Chinese)
     {
         this.nsc = new ChineseNumberSequenceClassifier(new Properties(), useSUTime, nscProps);
     }
     else
     {
         this.nsc = new NumberSequenceClassifier(new Properties(), useSUTime, nscProps);
     }
     if (augmentRegexNER)
     {
         this.gazetteMapping = ReadRegexnerGazette(DefaultPaths.DefaultNerGazetteMapping);
     }
     else
     {
         this.gazetteMapping = Java.Util.Collections.EmptyMap();
     }
 }
Beispiel #2
0
        /// <summary>
        /// This factory method is used to create the NERClassifierCombiner used in NERCombinerAnnotator
        /// (and, thence, in StanfordCoreNLP).
        /// </summary>
        /// <param name="name">
        /// A "x.y" format property name prefix (the "x" part). This is commonly null,
        /// and then "ner" is used.  If it is the empty string, then no property prefix is used.
        /// </param>
        /// <param name="passDownProperties">
        /// Property names for which the property should be passed down
        /// to the NERClassifierCombiner. The default is not to pass down, but pass down is
        /// useful for things like charset encoding.
        /// </param>
        /// <param name="properties">
        /// Various properties, including a list in "ner.model".
        /// The used ones start with name + "." or are in passDownProperties
        /// </param>
        /// <returns>An NERClassifierCombiner with the given properties</returns>
        public static NERClassifierCombiner CreateNERClassifierCombiner(string name, ICollection <string> passDownProperties, Properties properties)
        {
            string prefix     = (name == null) ? "ner." : name.IsEmpty() ? string.Empty : name + '.';
            string modelNames = properties.GetProperty(prefix + "model");

            if (modelNames == null)
            {
                modelNames = DefaultPaths.DefaultNerThreeclassModel + ',' + DefaultPaths.DefaultNerMucModel + ',' + DefaultPaths.DefaultNerConllModel;
            }
            // but modelNames can still be empty string is set explicitly to be empty!
            string[] models;
            if (!modelNames.IsEmpty())
            {
                models = modelNames.Split(",");
            }
            else
            {
                // Allow for no real NER model - can just use numeric classifiers or SUTime
                log.Info("WARNING: no NER models specified");
                models = StringUtils.EmptyStringArray;
            }
            NERClassifierCombiner nerCombiner;

            try
            {
                bool       applyNumericClassifiers = PropertiesUtils.GetBool(properties, prefix + ApplyNumericClassifiersPropertyBase, ApplyNumericClassifiersDefault);
                bool       useSUTime     = PropertiesUtils.GetBool(properties, prefix + NumberSequenceClassifier.UseSutimePropertyBase, NumberSequenceClassifier.UseSutimeDefault);
                bool       applyRegexner = PropertiesUtils.GetBool(properties, NERClassifierCombiner.ApplyGazetteProperty, NERClassifierCombiner.ApplyGazetteDefault);
                Properties combinerProperties;
                if (passDownProperties != null)
                {
                    combinerProperties = PropertiesUtils.ExtractSelectedProperties(properties, passDownProperties);
                    if (useSUTime)
                    {
                        // Make sure SUTime parameters are included
                        Properties sutimeProps = PropertiesUtils.ExtractPrefixedProperties(properties, NumberSequenceClassifier.SutimeProperty + ".", true);
                        PropertiesUtils.OverWriteProperties(combinerProperties, sutimeProps);
                    }
                }
                else
                {
                    // if passDownProperties is null, just pass everything through
                    combinerProperties = properties;
                }
                //Properties combinerProperties = PropertiesUtils.extractSelectedProperties(properties, passDownProperties);
                NERClassifierCombiner.Language nerLanguage = NERClassifierCombiner.Language.FromString(properties.GetProperty(prefix + "language"), NERClassifierCombiner.Language.English);
                nerCombiner = new NERClassifierCombiner(applyNumericClassifiers, nerLanguage, useSUTime, applyRegexner, combinerProperties, models);
            }
            catch (IOException e)
            {
                throw new RuntimeIOException(e);
            }
            return(nerCombiner);
        }
Beispiel #3
0
 public static NERClassifierCombiner.Language FromString(string name, NERClassifierCombiner.Language defaultValue)
 {
     if (name != null)
     {
         foreach (NERClassifierCombiner.Language l in NERClassifierCombiner.Language.Values())
         {
             if (Sharpen.Runtime.EqualsIgnoreCase(name, l.languageName))
             {
                 return(l);
             }
         }
     }
     return(defaultValue);
 }
Beispiel #4
0
 public NERClassifierCombiner(bool applyNumericClassifiers, bool useSUTime, bool augmentRegexNER, params AbstractSequenceClassifier <CoreLabel>[] classifiers)
     : base(classifiers)
 {
     this.applyNumericClassifiers = applyNumericClassifiers;
     this.nerLanguage             = NerLanguageDefault;
     this.useSUTime = useSUTime;
     this.nsc       = new NumberSequenceClassifier(useSUTime);
     if (augmentRegexNER)
     {
         this.gazetteMapping = ReadRegexnerGazette(DefaultPaths.DefaultNerGazetteMapping);
     }
     else
     {
         this.gazetteMapping = Java.Util.Collections.EmptyMap();
     }
 }
Beispiel #5
0
 /// <exception cref="System.IO.IOException"/>
 public NERClassifierCombiner(Properties props)
     : base(props)
 {
     // todo [cdm 2015]: Could avoid constructing this if applyNumericClassifiers is false
     applyNumericClassifiers = PropertiesUtils.GetBool(props, ApplyNumericClassifiersProperty, ApplyNumericClassifiersDefault);
     nerLanguage             = NERClassifierCombiner.Language.FromString(PropertiesUtils.GetString(props, NerLanguageProperty, null), NerLanguageDefault);
     useSUTime = PropertiesUtils.GetBool(props, NumberSequenceClassifier.UseSutimeProperty, NumberSequenceClassifier.UseSutimeDefault);
     nsc       = new NumberSequenceClassifier(new Properties(), useSUTime, props);
     if (PropertiesUtils.GetBool(props, NERClassifierCombiner.ApplyGazetteProperty, NERClassifierCombiner.ApplyGazetteDefault))
     {
         this.gazetteMapping = ReadRegexnerGazette(DefaultPaths.DefaultNerGazetteMapping);
     }
     else
     {
         this.gazetteMapping = Java.Util.Collections.EmptyMap();
     }
 }
Beispiel #6
0
        /// <exception cref="System.IO.IOException"/>
        /// <exception cref="System.InvalidCastException"/>
        /// <exception cref="System.TypeLoadException"/>
        public NERClassifierCombiner(ObjectInputStream ois, Properties props)
            : base(ois, props)
        {
            // constructor which builds an NERClassifierCombiner from an ObjectInputStream
            // read the useSUTime from disk
            bool diskUseSUTime = ois.ReadBoolean();

            if (props.GetProperty("ner.useSUTime") != null)
            {
                this.useSUTime = bool.Parse(props.GetProperty("ner.useSUTime"));
            }
            else
            {
                this.useSUTime = diskUseSUTime;
            }
            // read the applyNumericClassifiers from disk
            bool diskApplyNumericClassifiers = ois.ReadBoolean();

            if (props.GetProperty("ner.applyNumericClassifiers") != null)
            {
                this.applyNumericClassifiers = bool.Parse(props.GetProperty("ner.applyNumericClassifiers"));
            }
            else
            {
                this.applyNumericClassifiers = diskApplyNumericClassifiers;
            }
            this.nerLanguage = NerLanguageDefault;
            // build the nsc, note that initProps should be set by ClassifierCombiner
            this.nsc = new NumberSequenceClassifier(new Properties(), useSUTime, props);
            if (PropertiesUtils.GetBool(props, NERClassifierCombiner.ApplyGazetteProperty, NERClassifierCombiner.ApplyGazetteDefault))
            {
                this.gazetteMapping = ReadRegexnerGazette(DefaultPaths.DefaultNerGazetteMapping);
            }
            else
            {
                this.gazetteMapping = Java.Util.Collections.EmptyMap();
            }
        }