Exemplo n.º 1
0
        /// <summary>
        /// Tests this node
        /// </summary>
        public override void Test()
        {
            if (IsRoot)
            {
                RoleSet roleSet = RoleSet;
                if (roleSet != null)
                {
                    foreach (Role role in roleSet)
                    {
                        if (roleSet.Get(role.Number).Description != role.Description)
                        {
                            throw new Exception();
                        }
                    }
                }
            }

            IEnumerator <TreeBankNode> children = Children;

            while (children.MoveNext())
            {
                children.Current.Test();
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Adds a role set to this frame
 /// </summary>
 /// <param name="roleSet">Role set to add</param>
 public void AddRoleSet(RoleSet roleSet)
 {
     _idRoleSet.Add(roleSet.ID, roleSet);
 }
Exemplo n.º 3
0
        /// <summary>
        /// Builds the Frame index
        /// </summary>
        /// <param name="framesDirectory">Directory containing PropBank frame XML files</param>
        /// <returns>Frame index - a map from verb lemma to corresponding frame</returns>
        private static Dictionary <string, Frame> BuildFrameIndex(string framesDirectory)
        {
            if (!Directory.Exists(framesDirectory))
            {
                throw new Exception("Invalid frame directory:  \"" + framesDirectory + "\"");
            }

            // build index
            Dictionary <string, Frame> frameIndex = new Dictionary <string, Frame>();

            // get each frame file
            foreach (string frameFilePath in Directory.GetFiles(framesDirectory))
            {
                Frame currFrame = null;

                // read entire file and create XML parser
                StreamReader frameFile = new StreamReader(frameFilePath);
                string       frameXML  = frameFile.ReadToEnd();
                frameFile.Close();
                XmlParser frameP = new XmlParser(frameXML);

                // get role sets
                string roleSetXML;
                while ((roleSetXML = frameP.OuterXML("roleset")) != null)
                {
                    XmlParser roleSetP = new XmlParser(roleSetXML);

                    // get role set ID string in verb.id format
                    string roleSetIdStr = roleSetP.AttributeValue("roleset", "id").Trim();
                    int    dotIndex     = roleSetIdStr.IndexOf('.');

                    // get role set verb
                    string roleSetVerb = roleSetIdStr.Substring(0, dotIndex);

                    // if this is the first role set, create the frame
                    if (currFrame == null)
                    {
                        currFrame = new Frame(roleSetVerb);
                    }
                    // all role sets must use the same verb
                    else if (roleSetVerb != currFrame.Verb)
                    {
                        throw new Exception("Role set verb mismatch");
                    }

                    // get role set ID/name and create role set
                    int     roleSetID   = int.Parse(roleSetIdStr.Substring(dotIndex + 1));
                    string  roleSetName = roleSetP.AttributeValue("roleset", "name");
                    RoleSet roleSet     = new RoleSet(roleSetID, roleSetName);

                    // get roles
                    string roleXML;
                    while ((roleXML = roleSetP.OuterXML("role")) != null)
                    {
                        XmlParser roleP = new XmlParser(roleXML);

                        string description = roleP.AttributeValue("role", "descr");
                        string roleNumber  = roleP.AttributeValue("role", "n").ToLower();

                        // skip modifier and agentive modifier
                        if (roleNumber == "m" || roleNumber == "a")
                        {
                            continue;
                        }

                        Role role = new Role(description, int.Parse(roleNumber));
                        roleSet.Add(role);
                    }

                    // add role set to frame
                    currFrame.AddRoleSet(roleSet);
                }

                frameIndex.Add(currFrame.Verb, currFrame);
            }

            return(frameIndex);
        }