예제 #1
0
        public PartialViewResult _Index(QueryOntology queryOntology)
        {
            IGraph g = new Graph();

            StreamReader   file           = new StreamReader("Config.json");
            JsonSerializer serializer     = new JsonSerializer();
            var            configurations = JsonConvert.DeserializeObject <Configuration>(file.ReadToEnd());

            if (queryOntology.Ontology == 1)
            {
                g.LoadFromFile(configurations.InstagramPath);
            }
            else
            {
                g.LoadFromFile(configurations.MyHeritagePath);
            }

            try
            {
                Object results = g.ExecuteQuery(queryOntology.Query);
                //Object results = g.ExecuteQuery( "SELECT DISTINCT ?Concept WHERE {[] a ?Concept}");
                if (results is SparqlResultSet)
                {
                    SparqlResultSet rset = (SparqlResultSet)results;

                    var result = rset.Select(s => new ResultQueryList
                    {
                        Object    = s.ToString(),
                        Predicate = s.ToString(),
                        Subject   = s.ToString()
                    });
                    return(PartialView(result));
                }
                else if (results is IGraph)
                {
                    IGraph resGraph = (IGraph)results;
                    var    result   = resGraph.Triples.Select(s => new ResultQueryList
                    {
                        Object    = s.Object.ToString(),
                        Predicate = s.Predicate.ToString(),
                        Subject   = s.Subject.ToString()
                    });
                    return(PartialView(result));
                }
                else
                {
                    Console.WriteLine("ERROR");
                }
            }
            catch (RdfQueryException queryEx)
            {
                Console.WriteLine(queryEx.Message);
            }
            return(PartialView());
        }
예제 #2
0
        public PartialViewResult _Index(QueryOntology queryOntology)
        {
            List <string> queryResult = new List <string>();
            string        result      = "";
            int           bytesRec    = 0;

            string ontologyPath = "";

            if (queryOntology.Ontology == 1)
            {
                ontologyPath = configurations.InstagramPath;
            }
            else
            {
                ontologyPath = configurations.MyHeritagePath;
            }

            try
            {
                sender.Connect(remoteEP);
                var objectToSend = JsonConvert.SerializeObject(new { path = ontologyPath, query = queryOntology.Query });

                byte[] msg       = Encoding.ASCII.GetBytes(objectToSend + "\n");
                int    bytesSent = sender.Send(msg);

                while ((bytesRec = sender.Receive(bytes)) > 0)
                {
                    result = Encoding.ASCII.GetString(bytes, 0, bytesRec);
                    if (result == "\n")
                    {
                        break;
                    }
                    queryResult.Add(result);
                }

                sender.Shutdown(SocketShutdown.Both);
                sender.Close();
            }
            catch (ArgumentNullException ane)
            {
                Console.WriteLine("ArgumentNullException : {0}", ane.ToString());
            }
            catch (SocketException se)
            {
                Console.WriteLine("SocketException : {0}", se.ToString());
            }
            catch (Exception e)
            {
                Console.WriteLine("Unexpected exception : {0}", e.ToString());
            }
            return(PartialView(queryResult));
        }
예제 #3
0
        public JsonResult _ExecuteSPARQL(QueryOntology queryOntology)
        {
            IGraph g = new Graph();

            StreamReader   file           = new StreamReader("Config.json");
            JsonSerializer serializer     = new JsonSerializer();
            var            configurations = JsonConvert.DeserializeObject <Configuration>(file.ReadToEnd());

            if (queryOntology.Ontology == 1)
            {
                g.LoadFromFile(configurations.InstagramPath);
            }
            else
            {
                g.LoadFromFile(configurations.MyHeritagePath);
            }

            try
            {
                Object results = g.ExecuteQuery(queryOntology.Query);
                if (results is SparqlResultSet)
                {
                    SparqlResultSet rset   = (SparqlResultSet)results;
                    var             result = rset.Select(s => new ResultQueryList
                    {
                        Object    = s.ToString(),
                        Predicate = s.ToString(),
                        Subject   = s.ToString()
                    });
                    return(Json(JsonConvert.SerializeObject(rset)));
                }
                else if (results is IGraph)
                {
                    IGraph resGraph = (IGraph)results;
                    return(Json(resGraph.Triples));
                }
                else
                {
                    return(Json(false));
                }
            }
            catch (RdfQueryException queryEx)
            {
                return(Json(queryEx));
            }
        }