Ejemplo n.º 1
0
 public AceEntityMention(string id, string type, string ldctype, AceCharSeq extent, AceCharSeq head)
     : base(id, extent)
 {
     mType              = type;
     mLdctype           = ldctype;
     mHead              = head;
     mExtent            = extent;
     mHeadTokenPosition = -1;
     mParent            = null;
     mRelationMentions  = new List <AceRelationMention>();
     mEventMentions     = new List <AceEventMention>();
 }
        // buf.toString(),
        /// <summary>Makes an ACE entity from the span [startToken, endToken)</summary>
        private void MakeEntity(int startToken, int endToken, int id, string type, string subtype)
        {
            string    eid = mId + "-E" + id;
            AceEntity ent = new AceEntity(eid, type, subtype, "SPC");

            AddEntity(ent);
            AceCharSeq       cseq = MakeCharSeq(startToken, endToken);
            string           emid = mId + "-E" + id + "-1";
            AceEntityMention entm = new AceEntityMention(emid, "NOM", "NOM", cseq, cseq);

            AddEntityMention(entm);
            ent.AddMention(entm);
        }
        public virtual string ToXml(int offset)
        {
            StringBuilder buffer = new StringBuilder();

            AppendOffset(buffer, offset);
            buffer.Append("<?xml version=\"1.0\"?>\n");
            AppendOffset(buffer, offset);
            buffer.Append("<!DOCTYPE source_file SYSTEM \"apf.v5.1.2.dtd\">\n");
            AppendOffset(buffer, offset);
            buffer.Append("<source_file URI=\"" + mId + ".sgm\" SOURCE=\"" + mSource + "\" TYPE=\"text\" AUTHOR=\"LDC\" ENCODING=\"UTF-8\">\n");
            AppendOffset(buffer, offset);
            buffer.Append("<document DOCID=\"" + GetId() + "\">\n");
            // display all entities
            ICollection <string> entKeys = mEntities.Keys;

            foreach (string key in entKeys)
            {
                AceEntity e = mEntities[key];
                buffer.Append(e.ToXml(offset));
                buffer.Append("\n");
            }
            // display all relations
            ICollection <string> relKeys = mRelations.Keys;

            foreach (string key_1 in relKeys)
            {
                AceRelation r = mRelations[key_1];
                if (!r.GetType().Equals(AceRelation.NilLabel))
                {
                    buffer.Append(r.ToXml(offset));
                    buffer.Append("\n");
                }
            }
            // TODO: display all events
            AppendOffset(buffer, offset);
            buffer.Append("</document>\n");
            AppendOffset(buffer, offset);
            buffer.Append("</source_file>\n");
            return(buffer.ToString());
        }
Ejemplo n.º 4
0
        /// <summary>Parses one ACE specification</summary>
        /// <returns>Simply displays the events to stdout</returns>
        /// <exception cref="System.IO.IOException"/>
        /// <exception cref="Org.Xml.Sax.SAXException"/>
        /// <exception cref="Javax.Xml.Parsers.ParserConfigurationException"/>
        public static AceDocument ParseDocument(File f)
        {
            // parse the Dom document
            IDocument document = ReadDocument(f);
            //
            // create the ACE document object
            //
            INode       docElement = document.GetElementsByTagName("document").Item(0);
            AceDocument aceDoc     = new AceDocument(GetAttributeValue(docElement, "DOCID"));
            //
            // read all entities
            //
            INodeList entities    = document.GetElementsByTagName("entity");
            int       entityCount = 0;

            for (int i = 0; i < entities.GetLength(); i++)
            {
                INode node = entities.Item(i);
                //
                // the entity type and subtype
                //
                string id      = GetAttributeValue(node, "ID");
                string type    = GetAttributeValue(node, "TYPE");
                string subtype = GetAttributeValue(node, "SUBTYPE");
                string cls     = GetAttributeValue(node, "CLASS");
                // create the entity
                AceEntity entity = new AceEntity(id, type, subtype, cls);
                aceDoc.AddEntity(entity);
                // fetch all mentions of this event
                IList <INode> mentions = GetChildrenByName(node, "entity_mention");
                // parse all its mentions
                foreach (INode mention1 in mentions)
                {
                    AceEntityMention mention = ParseEntityMention(mention1);
                    entity.AddMention(mention);
                    aceDoc.AddEntityMention(mention);
                }
                entityCount++;
            }
            //log.info("Parsed " + entityCount + " XML entities.");
            //
            // read all relations
            //
            INodeList relations = document.GetElementsByTagName("relation");

            for (int i_1 = 0; i_1 < relations.GetLength(); i_1++)
            {
                INode node = relations.Item(i_1);
                //
                // the relation type, subtype, tense, and modality
                //
                string id       = GetAttributeValue(node, "ID");
                string type     = GetAttributeValue(node, "TYPE");
                string subtype  = GetAttributeValue(node, "SUBTYPE");
                string modality = GetAttributeValue(node, "MODALITY");
                string tense    = GetAttributeValue(node, "TENSE");
                // create the relation
                AceRelation relation = new AceRelation(id, type, subtype, modality, tense);
                aceDoc.AddRelation(relation);
                // XXX: fetch relation_arguments here!
                // fetch all mentions of this relation
                IList <INode> mentions = GetChildrenByName(node, "relation_mention");
                // traverse all mentions
                foreach (INode mention1 in mentions)
                {
                    AceRelationMention mention = ParseRelationMention(mention1, aceDoc);
                    relation.AddMention(mention);
                    aceDoc.AddRelationMention(mention);
                }
            }
            //
            // read all events
            //
            INodeList events = document.GetElementsByTagName("event");

            for (int i_2 = 0; i_2 < events.GetLength(); i_2++)
            {
                INode node = events.Item(i_2);
                //
                // the event type, subtype, tense, and modality
                //
                string id         = GetAttributeValue(node, "ID");
                string type       = GetAttributeValue(node, "TYPE");
                string subtype    = GetAttributeValue(node, "SUBTYPE");
                string modality   = GetAttributeValue(node, "MODALITY");
                string polarity   = GetAttributeValue(node, "POLARITY");
                string genericity = GetAttributeValue(node, "GENERICITY");
                string tense      = GetAttributeValue(node, "TENSE");
                // create the event
                AceEvent @event = new AceEvent(id, type, subtype, modality, polarity, genericity, tense);
                aceDoc.AddEvent(@event);
                // fetch all mentions of this relation
                IList <INode> mentions = GetChildrenByName(node, "event_mention");
                // traverse all mentions
                foreach (INode mention1 in mentions)
                {
                    AceEventMention mention = ParseEventMention(mention1, aceDoc);
                    @event.AddMention(mention);
                    aceDoc.AddEventMention(mention);
                }
            }
            return(aceDoc);
        }
Ejemplo n.º 5
0
 public virtual void SetParent(AceEntity e)
 {
     mParent = e;
 }
 public virtual void AddEntity(AceEntity e)
 {
     mEntities[e.GetId()] = e;
 }