Exemplo n.º 1
0
        public HCObjectSet <T> Union(IEnumerable <T> items)
        {
            HCObjectSet <T> result = new HCObjectSet <T>(this);

            result.AddMany(items);
            return(result);
        }
Exemplo n.º 2
0
        public override bool IsMatch(ValueInstance other)
        {
            ClosedValueInstance        vi           = other as ClosedValueInstance;
            HCObjectSet <FeatureValue> intersection = m_values.Intersection(vi.m_values);

            return(intersection.Count > 0);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="WordSynthesis"/> class.
        /// </summary>
        /// <param name="rootAllomorph">The root allomorph.</param>
        /// <param name="nonHead">The non-head synthesis.</param>
        /// <param name="rzFeatures">The realizational features.</param>
        /// <param name="mrules">The morphological rules to apply.</param>
        /// <param name="curTrace">The current trace record.</param>
        internal WordSynthesis(LexEntry.RootAllomorph rootAllomorph, WordSynthesis nonHead, FeatureValues rzFeatures, IEnumerable <MorphologicalRule> mrules,
                               Trace curTrace)
        {
            m_root        = (LexEntry)rootAllomorph.Morpheme;
            m_mprFeatures = m_root.MPRFeatures != null?m_root.MPRFeatures.Clone() : new MPRFeatureSet();

            m_headFeatures = m_root.HeadFeatures != null?m_root.HeadFeatures.Clone() : new FeatureValues();

            m_footFeatures = m_root.FootFeatures != null?m_root.FootFeatures.Clone() : new FeatureValues();

            m_pos     = m_root.POS;
            m_stratum = m_root.Stratum;

            m_nonHead = nonHead;
            m_morphs  = new Morphs();
            Morph morph = new Morph(rootAllomorph);

            morph.Shape.AddMany(rootAllomorph.Shape.Segments);
            m_morphs.Add(morph);
            m_shape = new PhoneticShape();
            m_shape.Add(new Margin(Direction.LEFT));
            m_shape.AddPartition(rootAllomorph.Shape.Segments, morph.Partition);
            m_shape.Add(new Margin(Direction.RIGHT));

            m_obligHeadFeatures = new HCObjectSet <Feature>();
            m_mrules            = new List <MorphologicalRule>(mrules);
            m_rzFeatures        = rzFeatures;
            m_curTrace          = curTrace;
            m_mrulesApplied     = new Dictionary <MorphologicalRule, int>();
        }
Exemplo n.º 4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Stratum"/> class.
 /// </summary>
 /// <param name="featId">The ID.</param>
 /// <param name="desc">The description.</param>
 /// <param name="morpher">The morpher.</param>
 public Stratum(string id, string desc, Morpher morpher)
     : base(id, desc, morpher)
 {
     m_mrules    = new HCObjectSet <MorphologicalRule>();
     m_prules    = new HCObjectSet <PhonologicalRule>();
     m_templates = new HCObjectSet <AffixTemplate>();
     m_entryTrie = new SegmentDefinitionTrie <LexEntry.RootAllomorph>(Direction.RIGHT);
 }
Exemplo n.º 5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="WordAnalysis"/> class.
 /// </summary>
 /// <param name="shape">The shape.</param>
 /// <param name="curTrace">The current trace record.</param>
 internal WordAnalysis(PhoneticShape shape, Stratum stratum, Trace curTrace)
 {
     m_shape           = shape;
     m_pos             = new HCObjectSet <PartOfSpeech>();
     m_mrules          = new List <MorphologicalRule>();
     m_mrulesUnapplied = new Dictionary <MorphologicalRule, int>();
     m_rzFeatures      = new FeatureValues();
     m_stratum         = stratum;
     m_curTrace        = curTrace;
 }
Exemplo n.º 6
0
        public HCObjectSet <T> Difference(IEnumerable <T> items)
        {
            HCObjectSet <T> result = new HCObjectSet <T>();

            foreach (T item in items)
            {
                if (!Contains(item))
                {
                    result.Add(item);
                }
            }
            return(result);
        }
Exemplo n.º 7
0
        public HCObjectSet <T> Intersection(IEnumerable <T> items)
        {
            HCObjectSet <T> result = new HCObjectSet <T>();

            foreach (T item in items)
            {
                if (Contains(item))
                {
                    result.Add(item);
                }
            }
            return(result);
        }
Exemplo n.º 8
0
        public override void Reset()
        {
            base.Reset();

            m_requiredPOSs         = null;
            m_outPOS               = null;
            m_maxNumApps           = 1;
            m_requiredHeadFeatures = null;
            m_requiredFootFeatures = null;
            m_outHeadFeatures      = null;
            m_outFootFeatures      = null;
            m_obligHeadFeatures    = null;
            m_subrules.Clear();
        }
Exemplo n.º 9
0
 /// <summary>
 /// Copy constructor.
 /// </summary>
 /// <param name="wa">The word analysis.</param>
 public WordAnalysis(WordAnalysis wa)
 {
     m_shape         = wa.m_shape.Clone();
     m_pos           = new HCObjectSet <PartOfSpeech>(wa.m_pos);
     m_rootAllomorph = wa.m_rootAllomorph;
     if (wa.m_nonHead != null)
     {
         m_nonHead = wa.m_nonHead.Clone();
     }
     m_mrules          = new List <MorphologicalRule>(wa.m_mrules);
     m_mrulesUnapplied = new Dictionary <MorphologicalRule, int>(wa.m_mrulesUnapplied);
     m_rzFeatures      = wa.m_rzFeatures.Clone();
     m_curTrace        = wa.m_curTrace;
     m_stratum         = wa.m_stratum;
 }
Exemplo n.º 10
0
        public override bool Unify(ValueInstance other, out ValueInstance output)
        {
            ClosedValueInstance vi = other as ClosedValueInstance;

            HCObjectSet <FeatureValue> intersection = m_values.Intersection(vi.m_values);

            if (intersection.Count > 0)
            {
                output = new ClosedValueInstance(intersection);
                return(true);
            }
            else
            {
                output = null;
                return(false);
            }
        }
Exemplo n.º 11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Morpher"/> class.
 /// </summary>
 /// <param name="id">The id.</param>
 /// <param name="language">The language.</param>
 public Morpher(string id, string language)
     : base(id, language, null)
 {
     m_strata          = new HCObjectSet <Stratum>();
     m_phoneticFeatSys = new FeatureSystem();
     m_headFeatSys     = new FeatureSystem();
     m_footFeatSys     = new FeatureSystem();
     m_charDefTables   = new HCObjectSet <CharacterDefinitionTable>();
     m_natClasses      = new HCObjectSet <NaturalClass>();
     m_prules          = new HCObjectSet <PhonologicalRule>();
     m_mrules          = new HCObjectSet <MorphologicalRule>();
     m_lexicon         = new Lexicon();
     m_templates       = new HCObjectSet <AffixTemplate>();
     m_mprFeatGroups   = new HCObjectSet <MPRFeatureGroup>();
     m_mprFeatures     = new HCObjectSet <MPRFeature>();
     m_pos             = new HCObjectSet <PartOfSpeech>();
     m_allomorphs      = new HCObjectSet <Allomorph>();
 }
Exemplo n.º 12
0
 /// <summary>
 /// Copy constructor.
 /// </summary>
 /// <param name="ws">The word synthesis.</param>
 public WordSynthesis(WordSynthesis ws)
 {
     m_root = ws.m_root;
     if (ws.m_nonHead != null)
     {
         m_nonHead = ws.m_nonHead.Clone();
     }
     m_shape             = ws.m_shape.Clone();
     m_morphs            = ws.m_morphs.Clone();
     m_pos               = ws.m_pos;
     m_mprFeatures       = ws.m_mprFeatures.Clone();
     m_headFeatures      = ws.m_headFeatures.Clone();
     m_footFeatures      = ws.m_footFeatures.Clone();
     m_obligHeadFeatures = new HCObjectSet <Feature>(ws.m_obligHeadFeatures);
     m_mrules            = new List <MorphologicalRule>(ws.m_mrules);
     m_curRuleIndex      = ws.m_curRuleIndex;
     m_rzFeatures        = ws.m_rzFeatures.Clone();
     m_curTrace          = ws.m_curTrace;
     m_stratum           = ws.m_stratum;
     m_mrulesApplied     = new Dictionary <MorphologicalRule, int>(ws.m_mrulesApplied);
 }
Exemplo n.º 13
0
        public bool Equals(HCObjectSet <T> other)
        {
            if (other == null)
            {
                return(false);
            }

            if (Count != other.Count)
            {
                return(false);
            }

            foreach (T item in this)
            {
                if (!other.Contains(item))
                {
                    return(false);
                }
            }

            return(true);
        }
Exemplo n.º 14
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MorphCoOccurrence"/> class.
 /// </summary>
 /// <param name="others">The other allomorphs or morphemes.</param>
 /// <param name="objectType">Type of the object.</param>
 /// <param name="adjacency">The adjacency.</param>
 public MorphCoOccurrence(IEnumerable <HCObject> others, ObjectType objectType, AdjacencyType adjacency)
 {
     m_others     = new HCObjectSet <HCObject>(others);
     m_objectType = objectType;
     m_adjacency  = adjacency;
 }
Exemplo n.º 15
0
 public MPRFeatureGroup(string id, string desc, Morpher morpher)
     : base(id, desc, morpher)
 {
     m_mprFeatures = new HCObjectSet <MPRFeature>();
 }
Exemplo n.º 16
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Slot"/> class.
 /// </summary>
 /// <param name="id">The ID.</param>
 /// <param name="desc">The description.</param>
 /// <param name="morpher">The morpher.</param>
 public Slot(string id, string desc, Morpher morpher)
     : base(id, desc, morpher)
 {
     m_rules = new HCObjectSet <MorphologicalRule>();
 }
Exemplo n.º 17
0
 public ClosedValueInstance(FeatureValue value)
 {
     m_values = new HCObjectSet <FeatureValue>();
     m_values.Add(value);
 }
Exemplo n.º 18
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BlockingTrace"/> class.
 /// </summary>
 /// <param name="pos">The part of speech of the stem.</param>
 /// <param name="requiredPOSs">The set of parts of speech this rule requires.</param>
 internal PhonologicalRuleSynthesisRequiredPOSTrace(PartOfSpeech pos, HCObjectSet <PartOfSpeech> requiredPOSs)
 {
     PartOfSpeech = pos;
     RequiredPOSs = requiredPOSs;
 }
Exemplo n.º 19
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AffixTemplate"/> class.
 /// </summary>
 /// <param name="id">The ID.</param>
 /// <param name="desc">The description.</param>
 /// <param name="morpher">The morpher.</param>
 public AffixTemplate(string id, string desc, Morpher morpher)
     : base(id, desc, morpher)
 {
     m_slots = new HCObjectSet <Slot>();
 }
Exemplo n.º 20
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Feature"/> class.
 /// </summary>
 /// <param name="id">The id.</param>
 /// <param name="desc">The description.</param>
 /// <param name="morpher">The morpher.</param>
 public Feature(string id, string desc, Morpher morpher)
     : base(id, desc, morpher)
 {
     m_possibleValues = new HCObjectSet <FeatureValue>();
     m_subFeatures    = new HCObjectSet <Feature>();
 }
Exemplo n.º 21
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FeatureSystem"/> class.
 /// </summary>
 public FeatureSystem()
 {
     m_features = new HCObjectSet <Feature>();
     m_values   = new HCObjectSet <FeatureValue>();
 }
Exemplo n.º 22
0
        /// <summary>
        /// Determines if all of the specified morphemes co-occur with the key morpheme.
        /// </summary>
        /// <param name="morphs">The morphs.</param>
        /// <param name="key">The key morpheme.</param>
        /// <returns></returns>
        public bool CoOccurs(Morphs morphs, HCObject key)
        {
            Collection <Morph>     morphList = morphs;
            HCObjectSet <HCObject> others    = new HCObjectSet <HCObject>(m_others);

            switch (m_adjacency)
            {
            case AdjacencyType.ANYWHERE:
                foreach (Morph morph in morphList)
                {
                    others.Remove(GetMorphObject(morph));
                }
                break;

            case AdjacencyType.SOMEWHERE_TO_LEFT:
            case AdjacencyType.ADJACENT_TO_LEFT:
                for (int i = 0; i < morphList.Count; i++)
                {
                    HCObject curMorphObj = GetMorphObject(morphList[i]);
                    if (key == curMorphObj)
                    {
                        break;
                    }
                    else if (others.Count > 0 && others[0] == curMorphObj)
                    {
                        if (m_adjacency == AdjacencyType.ADJACENT_TO_LEFT)
                        {
                            if (i == morphList.Count - 1)
                            {
                                return(false);
                            }

                            HCObject nextMorphObj = GetMorphObject(morphList[i + 1]);
                            if (others.Count > 1)
                            {
                                if (others[1] != nextMorphObj)
                                {
                                    return(false);
                                }
                            }
                            else if (key != nextMorphObj)
                            {
                                return(false);
                            }
                        }
                        others.RemoveAt(0);
                    }
                }
                break;

            case AdjacencyType.SOMEWHERE_TO_RIGHT:
            case AdjacencyType.ADJACENT_TO_RIGHT:
                for (int i = morphList.Count - 1; i >= 0; i--)
                {
                    HCObject curMorphObj = GetMorphObject(morphList[i]);
                    if (key == curMorphObj)
                    {
                        break;
                    }
                    else if (others.Count > 0 && others[others.Count - 1] == curMorphObj)
                    {
                        if (m_adjacency == AdjacencyType.ADJACENT_TO_RIGHT)
                        {
                            if (i == 0)
                            {
                                return(false);
                            }

                            HCObject prevMorphObj = GetMorphObject(morphList[i - 1]);
                            if (others.Count > 1)
                            {
                                if (others[others.Count - 2] != prevMorphObj)
                                {
                                    return(false);
                                }
                            }
                            else if (key != prevMorphObj)
                            {
                                return(false);
                            }
                        }
                        others.RemoveAt(others.Count - 1);
                    }
                }
                break;
            }

            return(others.Count == 0);
        }
Exemplo n.º 23
0
 public Loader()
 {
     m_morphers = new HCObjectSet <Morpher>();
 }
Exemplo n.º 24
0
 public LexFamily(string id, string desc, Morpher morpher)
     : base(id, desc, morpher)
 {
     m_entries = new HCObjectSet <LexEntry>();
 }
Exemplo n.º 25
0
 public Lexicon()
 {
     m_entries  = new HCObjectSet <LexEntry>();
     m_families = new HCObjectSet <LexFamily>();
 }
Exemplo n.º 26
0
 public ClosedValueInstance(IEnumerable <FeatureValue> values)
 {
     m_values = new HCObjectSet <FeatureValue>(values);
 }