示例#1
0
 protected virtual void Write(string localName, HCObject obj)
 {
     m_xmlWriter.WriteStartElement(localName);
     m_xmlWriter.WriteAttributeString("id", obj.ID);
     m_xmlWriter.WriteElementString("Description", obj.Description);
     m_xmlWriter.WriteEndElement();
 }
示例#2
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);
        }