Beispiel #1
0
        public static List <AMREduSentence> ReadIds(IGraph g)
        {
            var result = new List <AMREduSentence>();
            SparqlQueryParser qparser = new SparqlQueryParser();
            //Then we can parse a SPARQL string into a query
            SparqlQuery q = qparser.ParseFromString("SELECT ?s ?p WHERE { ?s <http://amr.isi.edu/rdf/core-amr#has-id> ?p }");

            var rset = (SparqlResultSet)g.ExecuteQuery(q);

            var SB = new StringBuilder();

            if (rset.Result && rset.Results.Count > 0)
            {
                foreach (var set in rset.Results)
                {
                    var sentence = new AMREduSentence();
                    foreach (var r in set)
                    {
                        if (r.Key == "s")
                        {
                            sentence.urlid = r.Value.GraphUri;
                        }
                        else
                        {
                            sentence.Id = int.Parse(r.Value.ToString());
                        }
                    }
                    result.Add(sentence);
                }
            }

            return(result.OrderBy(c => c.Id).ToList());
        }
 private void CreateRootRelation(IGraphClient client, AMREduSentence sentence, AMRNode Root)
 {
     client.Cypher.Match("(edu:EduSentence)", "(node:AMRNode)")
     .Where((AMREduSentence edu) => edu.Id == sentence.Id)
     .AndWhere((AMRNode node) => node.Id == Root.Id)
     .Create("(edu)-[:Root]->(node)").ExecuteWithoutResults();
 }
        public void SaveNode(IGraphClient client, AMRNode Node, AMRNode Parent, AMREduSentence Sentence)
        {
            this.CreateNode(client, Node);

            //NODE HAS
            //client.Cypher.Match("(node:AMRNode)", "(edunode:EduSentence)")
            //.Where((AmrNode node) => node.Id == Node.Id)
            //.AndWhere((EduSentence edunode) => edunode.Id == Sentence.Id)
            //.Create("(edunode)-[:HAS]->(node)").ExecuteWithoutResults();

            if (Parent != null)
            {
                if (Node.Direction)
                {
                    client.Cypher.Match("(node:AMRNode)", "(child:AMRNode)")
                    .Where((AMRNode node) => node.Id == Parent.Id)
                    .AndWhere((AMRNode child) => child.Id == Node.Id)
                    .Create(string.Format("(node)-[r:wordrel {{name:'{0}',inverse:{1}, url:'{2}', argname: '{3}' }}]->(child)", Node.RelationName, !Node.Direction, Node.Relation, CalculateRelationArgName(Parent, Node))).ExecuteWithoutResults();
                }
                else
                {
                    client.Cypher.Match("(node:AMRNode)", "(child:AMRNode)")
                    .Where((AMRNode node) => node.Id == Parent.Id)
                    .AndWhere((AMRNode child) => child.Id == Node.Id)
                    .Create(string.Format("(child)-[r:wordrel {{name:'{0}',inverse:{1}, url:'{2}', argname: '{3}' }}]->(node)", Node.RelationName, !Node.Direction, Node.Relation, CalculateRelationArgName(Parent, Node))).ExecuteWithoutResults();
                }
            }

            foreach (var child in Node.Nodes)
            {
                this.SaveNode(client, child, Node, Sentence);
            }
        }
Beispiel #4
0
        public void Load(IGraph graph)
        {
            SparqlQueryParser qparser  = new SparqlQueryParser();
            StringBuilder     querystr = new StringBuilder();

            querystr.AppendLine("PREFIX amr-core: <http://amr.isi.edu/rdf/core-amr#>");
            querystr.AppendLine("PREFIX amr-data: <http://amr.isi.edu/amr_data#>");
            querystr.AppendLine("PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>");
            querystr.AppendLine("PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>");
            querystr.AppendLine("PREFIX amr-terms: <http://amr.isi.edu/rdf/amr-terms#>");
            querystr.Append("SELECT ?s ?sentence ?id ");
            querystr.Append("WHERE {");
            querystr.Append("?s amr-core:has-sentence ?sentence.");
            querystr.Append("?s amr-core:has-id ?id");
            querystr.Append("}");

            SparqlQuery q    = qparser.ParseFromString(querystr.ToString());
            var         rset = (SparqlResultSet)graph.ExecuteQuery(q);

            var SB = new StringBuilder();

            if (rset.Result && rset.Results.Count > 0)
            {
                foreach (var result in rset.Results)
                {
                    var sentence = new AMREduSentence();
                    foreach (var r in result)
                    {
                        if (r.Key == "s")
                        {
                            sentence.urlid = ((UriNode)r.Value).Uri;
                        }
                        if (r.Key == "sentence")
                        {
                            sentence.value = r.Value.ToString();
                        }
                        if (r.Key == "id")
                        {
                            sentence.Id = int.Parse(r.Value.ToString());
                        }
                    }
                    this.EDUSentences.Add(sentence);
                    sentence.LoadRoot(graph);
                }
            }
        }
Beispiel #5
0
        public static String GetAmrNode(IGraph g, AMREduSentence sentence)
        {
            String            result  = string.Empty;
            SparqlQueryParser qparser = new SparqlQueryParser();
            var         str           = "SELECT ?p WHERE { <" + sentence.urlid + ">  <http://amr.isi.edu/rdf/core-amr#root> ?p }";
            SparqlQuery q             = qparser.ParseFromString(str);
            var         rset          = (SparqlResultSet)g.ExecuteQuery(q);
            var         SB            = new StringBuilder();

            if (rset.Result && rset.Results.Count > 0)
            {
                foreach (var set in rset.Results)
                {
                    foreach (var r in set)
                    {
                        result = r.Value.ToString();
                    }
                }
            }
            return(result);
        }