Exemple #1
0
        internal TLiteralNode(string rest_line, TGraph g)
        {
            this.g = g;
            // Последняя двойная кавычка
            int lastqu = rest_line.LastIndexOf('\"');

            // Значение данных
            var sdata = rest_line.Substring(1, lastqu - 1);

            // Языковый специализатор:
            int    dog  = rest_line.LastIndexOf('@');
            string lang = "";

            if (dog == lastqu + 1)
            {
                lang = rest_line.Substring(dog + 1, rest_line.Length - dog - 1);
            }

            string datatype = "";
            int    pp       = rest_line.IndexOf("^^");

            if (pp == lastqu + 1)
            {
                //  Тип данных
                string qname = rest_line.Substring(pp + 2);
                //  тип данных может быть "префиксным" или полным
                if (qname[0] == '<')
                {
                    datatype = qname.Substring(1, qname.Length - 2);
                }
                else
                {
                    datatype = TTurtleParser.GetEntityString(g, qname);
                }
            }
            Literal lit =
                datatype == "http://www.w3.org/2001/XMLSchema#integer" ?
                new Literal()
            {
                Vid = LiteralVidEnumeration.integer, Value = int.Parse(sdata)
            } :
            (datatype == "http://www.w3.org/2001/XMLSchema#date" ?
             new Literal()
            {
                Vid = LiteralVidEnumeration.date, Value = DateTime.Parse(sdata).ToBinary()
            } :
             (new Literal()
            {
                Vid = LiteralVidEnumeration.text, Value = new Text()
                {
                    Value = sdata, Lang = "en"
                }
            }));
            long off = g.AddLiteral(lit);

            this.ocode = off;
        }
Exemple #2
0
        public static void Main(string[] args)
        {
            Console.WriteLine("Start");
            string path   = @"..\..\..\Databases\";
            TGraph gra    = new TGraph(path);
            bool   toload = false;

            if (toload)
            {
                TTurtleParser parser = new TTurtleParser();
                parser.Load(gra, @"D:\home\FactographDatabases\dataset\dataset1M.ttl");
            }
            else
            {
                Tracer(gra);
            }
        }
Exemple #3
0
        public static void Main(string[] args)
        {
            Console.WriteLine("Start");
            string   path        = @"..\..\..\Databases\";
            string   datasetpath = @"D:\home\FactographDatabases\dataset\";
            DateTime tt0         = DateTime.Now;
            TGraph   gra         = new TGraph(path);

            Console.WriteLine("Построение графа: {0} мс.", (DateTime.Now - tt0).Ticks / 10000L); tt0 = DateTime.Now;
            bool toload = true;

            if (toload)
            {
                tt0 = DateTime.Now;
                TTurtleParser parser = new TTurtleParser();
                parser.Load(gra, datasetpath + "dataset100M.ttl");
                Console.WriteLine("TOTAL: {0} мс.", (DateTime.Now - tt0).Ticks / 10000L); tt0 = DateTime.Now;
            }
            else
            {
                Tracer(gra, datasetpath + @"tracing100th.xml");
            }
        }
Exemple #4
0
        private static void Tracer(TGraph graph, string tracingfile)
        {
            // Трассировка
            XElement tracing = XElement.Load(tracingfile);

            Console.WriteLine("N_tests = {0}", tracing.Elements().Count());
            DateTime tt0 = DateTime.Now;
            int      ecnt = 0, ncnt = 0;

            foreach (XElement spo in tracing.Elements())
            {
                XAttribute s_att = spo.Attribute("subj");
                XAttribute p_att = spo.Attribute("pred");
                XAttribute o_att = spo.Attribute("obj");
                XAttribute r_att = spo.Attribute("res");
                string     s     = s_att == null? null : s_att.Value;
                string     p     = p_att == null ? null : p_att.Value;
                string     o     = o_att == null ? null : o_att.Value;
                string     res   = r_att == null ? null : r_att.Value;
                if (spo.Name == "spo")
                {
                    bool r = graph.ContainsTriple(new Triple(
                                                      new TUriNode(s, graph),
                                                      new TUriNode(p, graph),
                                                      new TUriNode(o, graph)));
                    if ((res == "true" && r) || (res == "false" && !r))
                    {
                        ecnt++;
                    }
                    else
                    {
                        ncnt++;
                    }
                }
                else if (spo.Name == "spD")
                {
                    //IEnumerable<long> codes = graph.GetDataCodeBySubjPred(
                    //    s.GetHashCode(),
                    //    p.GetHashCode());
                    //Literal lit = null;
                    //// Несколько экзотичный способ получения FirstOrDefault()
                    //foreach (var litcode in codes)
                    //{
                    //    lit = graph.DecodeDataCode(litcode);
                    //    break;
                    //}
                    //if (lit == null) { ncnt++; }
                    //else
                    //{
                    //    bool isEq = false;
                    //    if (lit.Vid == LiteralVidEnumeration.text &&
                    //        ((Text)lit.Value).Value == res.Substring(1, res.Length - 2)) isEq = true;
                    //    else isEq = lit.ToString() == res;
                    //    if (isEq) ecnt++; else ncnt++;
                    //}
                }
                else if (spo.Name == "spO")
                {
                    var query = graph.GetTriplesWithSubjectPredicate(
                        new TUriNode(s, graph),
                        new TUriNode(p, graph)).ToArray();
                    if (query.Count() == 0 && res == "")
                    {
                        continue;
                    }
                    ecnt++;
                }
                else if (spo.Name == "Spo")
                {
                    var query = graph.GetTriplesWithPredicateObject(
                        new TUriNode(p, graph),
                        new TUriNode(o, graph)).ToArray();
                    if (query.Count() == 0 && res == "")
                    {
                        continue;
                    }
                    ecnt++;
                }
            }
            Console.WriteLine("TOTAL: {0} мс. ecnt={1} ncnt={2}", (DateTime.Now - tt0).Ticks / 10000L, ecnt, ncnt); tt0 = DateTime.Now;
        }
Exemple #5
0
 internal TLiteralNode(long code, TGraph g)
 {
     this.g     = g;
     this.ocode = code;
 }