Exemple #1
0
            public string check_word_for_property(Token word, string key)
            {
                if (word == null)
                {
                    return(null);
                }

                if (word.source.GetType() == typeof(Element_Item))
                {
                    Element_Item item = word.source as Element_Item;
                    if (!item.properties.ContainsKey(key))
                    {
                        return(check_word_for_property(word.parent, key));
                    }

                    return(item.properties[key]);
                }
                else
                {
                    Element_Word item = word.source as Element_Word;
                    if (!item.properties.ContainsKey(key))
                    {
                        if (parent.generated)
                        {
                            return(check_source_for_property(item.parent, key));
                        }
                        else
                        {
                            return(check_word_for_property(word.parent, key));
                        }
                    }

                    return(item.properties[key]);
                }
            }
Exemple #2
0
            public string check_source_for_property(Element_Base word, string key)
            {
                if (word == null)
                {
                    return(null);
                }

                if (word.GetType() == typeof(Element_Item))
                {
                    Element_Item item = word as Element_Item;
                    if (!item.properties.ContainsKey(key))
                    {
                        return(check_source_for_property(word.parent, key));
                    }

                    return(item.properties[key]);
                }
                else if (word.GetType() == typeof(Element_Word))
                {
                    Element_Word item = word as Element_Word;
                    if (!item.properties.ContainsKey(key))
                    {
                        return(check_source_for_property(word.parent, key));
                    }

                    return(item.properties[key]);
                }
                else
                {
                    return(check_source_for_property(word.parent, key));
                }
            }
        //public static void init()
        //{
        //    id = 0;
        //}

        //public void initialize()
        //{
        //    type = Element_Type.item;
        //}

        public static Element_Item create_rule(Familiar_Document new_document, XmlElement element)
        {
            Element_Item result = new Element_Item();

            result.document = new_document;
            result.initialize(element);
            return(result);
        }
        protected override void initialize(XmlElement element)
        {
            load(element);

            name = get_attribute(element, "id");
            //weight = get_attribute(element, "weight");

            if (element.HasAttribute("display"))
            {
                display = element.GetAttribute("display");
            }

            foreach (XmlAttribute attribute in element.Attributes)
            {
                if (!internal_attributes.Contains(attribute.Name))
                {
                    properties.Add(attribute.Name, attribute.Value);
                }
            }

            foreach (XmlNode child in element.ChildNodes)
            {
                if (child.NodeType == XmlNodeType.Element)
                {
                    XmlElement child_element = child as XmlElement;
                    if (child_element.Name.ToLower() == "suffix")
                    {
                        suffixes.Add(child_element.InnerText);
                    }
                    else
                    {
                        create_child(child_element);
                    }
                }
                else if (child.NodeType == XmlNodeType.Text)
                {
                    Element_Item item = (Element_Item)create_child(typeof(Element_Item));
                    item.text = child.InnerText.Trim();
                    //    word += child.InnerText.Trim();
                }
            }

            if (children.Count > 0 && children[0].GetType() == typeof(Element_Item) && children.Count == 1 &&
                children[0].children.Count == 0 && !document.all_rules.Contains(this))
            {
                Element_Item child = children[0] as Element_Item;

                if (child.display != null)
                {
                    display = child.display;
                }

                text = child.text;
                children.Clear();
            }

            //parse_properties(element);
        }
        public Element_Base create_child(XmlElement element)
        {
            Element_Base result = null;

            switch (element.Name.ToLower())
            {
            case "rule":
            {
                result = new Element_Item();
                document.all_rules.Add((Element_Item)result);
                break;
            }

            case "ruleref":
            case "reference":
                result = new Element_Reference();
                break;

            case "tag":
                result = new Element_Tag();
                break;

            case "item":
                result = new Element_Item();
                if (result.name != "")
                {
                    document.all_rules.Add((Element_Item)result);
                }
                break;

            case "one-of":
            case "choice":
                result = new Element_Choice();
                break;

            case "dictation":
                result = new Element_Dictation();
                break;

            case "word":
                result = new Element_Word();
                break;

            //case "filter":
            //    if (Familiar_Word.Filter.filters.has_key(element.InnerText))
            //        filters.Add(Familiar_Word.Filter.filters[element.InnerText]);
            //    return null;
            default:
                return(null);
            }

            add(result);
            result.initialize(element);
            return(result);
        }
 protected void load_children(XmlElement element)
 {
     foreach (XmlNode child in element.ChildNodes)
     {
         if (child.NodeType == XmlNodeType.Element)
         {
             create_child((XmlElement)child);
         }
         else if (child.NodeType == XmlNodeType.Text)
         {
             Element_Item item = (Element_Item)create_child(typeof(Element_Item));
             item.text = child.InnerText.Trim();
             //    word += child.InnerText.Trim();
         }
     }
 }
Exemple #7
0
            public bool contains_key(string key)
            {
                if (additions.ContainsKey(key))
                {
                    return(true);
                }

                if (parent.source.GetType() == typeof(Element_Item))
                {
                    Element_Item item = parent.source as Element_Item;
                    return(item.properties.ContainsKey(key));
                }
                else
                {
                    Element_Word item = parent.source as Element_Word;
                    return(item.properties.ContainsKey(key));
                }
            }
Exemple #8
0
        public Element_Word get_word(string text, string rule_name)
        {
            Element_Item rule = get_rule(rule_name);

            if (rule == null)
            {
                return(null);
            }

            foreach (Element_Word item in rule.children[0].get_children(typeof(Element_Word)))
            {
                if (item.match(text))
                {
                    return(item);
                }
            }

            return(null);
        }
Exemple #9
0
        public Element_Choice get_rule_choice(string rule_id)
        {
            Element_Item rule = get_rule(rule_id);

            if (rule == null)
            {
                return(null);
            }

            foreach (Element_Base element in rule.children)
            {
                if (element.GetType() == typeof(Element_Choice))
                {
                    return((Element_Choice)element);
                }
            }

            Element_Choice choices = (Element_Choice)rule.create_child(typeof(Element_Choice));

            rule.children.Add(choices);
            return(choices);
        }
Exemple #10
0
        public void load()
        {
            rules.Clear();
            all_rules.Clear();
            all_local_references.Clear();
            vocabulary.clear();
            referenced_documents.Clear();

            if (all_documents.Count == 0)
            {
                reset();
            }

            all_documents.Add(name, this);

            XmlDocument document = new XmlDocument();

            document.Load(file_name);
            XmlElement node = document.ChildNodes[1] as XmlElement;

            if (node.GetAttribute("priority").Length > 0)
            {
                priority = int.Parse(node.GetAttribute("priority"));
            }

            if (node.GetAttribute("no_spaces").Length > 0)
            {
                no_spaces = bool.Parse(node.GetAttribute("no_spaces"));
            }

            foreach (XmlElement rule in node.ChildNodes)
            {
                if (rule.Name.ToLower() == "rule" || rule.Name.ToLower() == "item")
                {
                    Element_Item result = Element_Item.create_rule(this, rule);
                    if (result != null)
                    {
                        rules.Add(result);
                        if (!all_rules.Contains(result))
                        {
                            all_rules.Add(result);
                        }
                    }
                }
            }

            synchronize_local_references();

            XmlNodeList commands = node.GetElementsByTagName("onload");

            foreach (XmlElement command in commands)
            {
                string type = command.GetAttribute("type");
                string code = "";
                foreach (XmlNode child in command.ChildNodes)
                {
                    code += child.InnerText;
                }

                onload = new Old_Action(this);
                onload.AddStep(type, code);
            }
        }