Esempio n. 1
0
 /// <summary>
 /// запускает Build и  замеряет время.
 /// </summary>
 /// <param name="graph"> тестируемый граф должен реализовать интерфейс <seealso cref="RDFCommon.IGraph<string,string,ObjectVariants>"/></param>
 /// <param name="turtleFileName"> путь к внешнему файлу ttl</param>
 public static void TestReadTtl(this IGraph <Triple <string, string, ObjectVariants> > graph, string turtleFileName)
 {
     Performance.ComputeTime(() =>
                             graph.Build(
                                 ReadTripleStringsFromTurtle.LoadGraph(turtleFileName)),
                             "build " + turtleFileName + " ", true);
 }
Esempio n. 2
0
 /// <summary>
 /// запускает Build и  замеряет время.
 /// </summary>
 /// <param name="graph"> тестируемый граф должен реализовать интерфейс <see cref="RDFCommon.IGraph<string,string,ObjectVariants>"/></param>
 /// <param name="millions">в данных пока предполагаются варианты: 1, 10, 100, 1000</param>
 public static void TestReadTtl(this IGraph <Triple <string, string, ObjectVariants> > graph, int millions)
 {
     Performance.ComputeTime(() =>
                             graph.Build(
                                 ReadTripleStringsFromTurtle.LoadGraph(
                                     Config.Source_data_folder_path + millions + ".ttl")), "build " + millions + ".ttl ", true);
 }
    private void Start()
    {
        switch (choiceOfBehavior)
        {
        case SteeringBehaviors.PathFinder:

            myRotateType           = new LookWhereGoing();
            myRotateType.character = this;
            myRotateType.target    = newTarget;
            myGraph = new MudGraph();
            myGraph.Build();
            List <Connection> path = Dijkstra.pathfind(myGraph, start, goal);
            // path is a list of connections - convert this to gameobjects for the FollowPath steering behavior
            myPath = new GameObject[path.Count + 1];
            int k = 0;
            foreach (Connection c in path)
            {
                Debug.Log("from " + c.getFromNode() + " to " + c.getToNode() + " @" + c.getCost());
                myPath[k] = c.getFromNode().gameObject;
                k++;
            }
            myPath[k]            = goal.gameObject;
            myMoveType           = new PathFollow();
            myMoveType.character = this;
            myMoveType.path      = myPath;
            break;
        }
    }
    // Start is called before the first frame update
    void Start()
    {
        kinematic              = GetComponent <Kinematic>();
        myRotateType           = new LookWhereGoing();
        myRotateType.character = kinematic;

        myGraph = new GraphTerrain();
        myGraph.Build();
        List <Connection> path = Dijkstra.pathfind(myGraph, start, goal);

        // path is a list of connections - convert this to gameobjects for the FollowPath steering behavior
        myPath = new Kinematic[path.Count + 1];
        int i = 0;

        foreach (Connection c in path)
        {
            Debug.Log("from " + c.getFromNode() + " to " + c.getToNode() + " @" + c.getCost());
            myPath[i] = c.getFromNode().GetComponent <Kinematic>();
            i++;
        }
        myPath[i] = goal.GetComponent <Kinematic>();

        myMoveType           = new PathFollow();
        myMoveType.character = kinematic;
        myMoveType.path      = myPath;
    }
Esempio n. 5
0
 /// <summary>
 /// запускает Build и  замеряет время.
 ///    использует <see cref="TripleGeneratorBufferedParallel"/>
 ///
 /// </summary>
 /// <param name="graph"> тестируемый граф должен реализовать интерфейс <see cref="RDFCommon.IGraph<string,string,ObjectVariants>"/></param>
 /// <param name="millions">в данных пока предполагаются варианты: 1, 10, 100, 1000</param>
 public static void TestReadTtl_Cocor(this IGraph <Triple <string, string, ObjectVariants> > graph, int millions)
 {
     Performance.ComputeTime(() =>
     {
         var generator = new TripleGeneratorBufferedParallel(Config.Source_data_folder_path + millions + ".ttl", "g");
         graph.Build(generator);
     },
                             "build " + millions + ".ttl ", true);
 }
Esempio n. 6
0
 /// <summary>
 /// запускает Build и  замеряет время.
 /// </summary>
 /// <param name="graph"> тестируемый граф должен реализовать интерфейс <seealso cref="RDFCommon.IGraph<string,string,ObjectVariants>"/></param>
 /// <param name="turtleFileName"> путь к внешнему файлу ttl</param>
 public static void TestReadTtl_Cocor(this IGraph <Triple <string, string, ObjectVariants> > graph, string turtleFileName)
 {
     Performance.ComputeTime(() =>
                             graph.Build(new TripleGeneratorBufferedParallel(turtleFileName, "g")),
                             "build " + turtleFileName + " ", true);
 }
Esempio n. 7
0
        public void LoadTriplets(IGraph graph, string datafile)
        {
            graph.Clear();


            int   ntriples          = 0;
            int   nTripletsInBuffer = 0;
            INode subject           = null;

            using (var sr = new StreamReader(datafile))
                while (!sr.EndOfStream)
                {
                    string line = sr.ReadLine();
                    if (line == "")
                    {
                        continue;
                    }
                    if (line[0] == '@')
                    {
                        // namespace
                        string[] parts = line.Split(' ');
                        if (parts.Length != 4 || parts[0] != "@prefix" || parts[3] != ".")
                        {
                            Console.WriteLine("Err: strange line: " + line);
                            continue;
                        }
                        string pref   = parts[1];
                        string nsname = parts[2];
                        if (nsname.Length < 3 || nsname[0] != '<' || nsname[nsname.Length - 1] != '>')
                        {
                            Console.WriteLine("Err: strange nsname: " + nsname);
                            continue;
                        }
                        nsname = nsname.Substring(1, nsname.Length - 2);
                        graph.NamespaceMap.AddNamespace(pref, new Uri(nsname));
                    }
                    else if (line[0] != ' ')
                    {
                        // Subject
                        line    = line.Trim();
                        subject = graph.CreateUriNode(line);
                    }
                    else
                    {
                        // Predicate and object
                        string line1       = line.Trim();
                        int    first_blank = line1.IndexOf(' ');
                        if (first_blank == -1)
                        {
                            Console.WriteLine("Err in line: " + line);
                            continue;
                        }

                        string rest_line = line1.Substring(first_blank + 1).Trim();
                        // Уберем последний символ
                        rest_line = rest_line.Substring(0, rest_line.Length - 1).Trim();
                        bool isDatatype = rest_line[0] == '\"';

                        string pred_line = line1.Substring(0, first_blank);
                        INode  predicate = graph.CreateUriNode(pred_line == "a" ? "<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>" : pred_line);

                        // объект может быть entity или данное, у данного может быть языковый спецификатор или тип
                        string sdata    = null;
                        string datatype = null;
                        string lang     = null;
                        if (isDatatype)
                        {
                            // Последняя двойная кавычка
                            int lastqu = rest_line.LastIndexOf('\"');
                            // Значение данных
                            sdata = rest_line.Substring(1, lastqu - 1);
                            // Языковый специализатор:
                            int dog = rest_line.LastIndexOf('@');
                            if (dog == lastqu + 1)
                            {
                                lang = rest_line.Substring(dog + 1, rest_line.Length - dog - 1);
                            }
                            int pp = rest_line.IndexOf("^^");
                            if (pp == lastqu + 1)
                            {
                                //  Тип данных
                                string qname = rest_line.Substring(pp + 2);
                                //  тип данных может быть "префиксным" или полным

                                datatype = "<" + qname + ">"; // rdf.NameSpaceStore.GetShortFromFullOrPrefixed(qname);
                            }

                            ILiteralNode literal = graph.CreateLiteralNode(rest_line);

                            graph.Assert(new Triple(subject, predicate, literal));
                        }
                        else
                        {
                            graph.Assert(new Triple(subject, predicate, graph.CreateUriNode(rest_line)));
                        }
                        ntriples++;
                        nTripletsInBuffer++;
                        if (ntriples % 100000 == 0)
                        {
                            Console.Write("r{0} ", ntriples / 100000);
                        }
                    }
                }

            graph.Build();

            Console.WriteLine("ntriples={0}", ntriples);
        }
Esempio n. 8
0
        public void Load(IGraph g, string datafile)
        {
            g.Clear();
            g.NamespaceMap.Clear(); // Возможно, это действие входит в предыдущее
            int    ntriples = 0;
            string subject  = null;

            //Dictionary<string, string> namespaces = new Dictionary<string, string>();
            System.IO.StreamReader sr = new System.IO.StreamReader(datafile);
            for (int i = 0; ; i++)
            {
                string line = sr.ReadLine();
                //if (i % 10000 == 0) { Console.Write("{0} ", i / 10000); }
                if (line == null)
                {
                    break;
                }
                if (line == "")
                {
                    continue;
                }
                if (line[0] == '@')
                { // namespace
                    string[] parts = line.Split(' ');
                    if (parts.Length != 4 || parts[0] != "@prefix" || parts[3] != ".")
                    {
                        Console.WriteLine("Err: strange line: " + line);
                        continue;
                    }
                    string pref   = parts[1];
                    string nsname = parts[2];
                    if (nsname.Length < 3 || nsname[0] != '<' || nsname[nsname.Length - 1] != '>')
                    {
                        Console.WriteLine("Err: strange nsname: " + nsname);
                        continue;
                    }
                    nsname = nsname.Substring(1, nsname.Length - 2);
                    //namespaces.Add(pref, nsname);
                    g.NamespaceMap.AddNamespace(pref, new Uri(nsname));
                }
                else if (line[0] != ' ')
                { // Subject
                    line    = line.Trim();
                    subject = GetEntityString(g, line);
                    if (subject == null)
                    {
                        continue;
                    }
                }
                else
                { // Predicate and object
                    string line1       = line.Trim();
                    int    first_blank = line1.IndexOf(' ');
                    if (first_blank == -1)
                    {
                        Console.WriteLine("Err in line: " + line); continue;
                    }
                    string pred_line = line1.Substring(0, first_blank);
                    if (pred_line == "a")
                    {
                        pred_line = "http://www.w3.org/1999/02/22-rdf-syntax-ns#type";
                    }
                    string predicate = GetEntityString(g, pred_line);
                    string rest_line = line1.Substring(first_blank + 1).Trim();
                    // Уберем последний символ (точку)
                    rest_line = rest_line.Substring(0, rest_line.Length - 1).Trim();
                    bool isDatatype = rest_line[0] == '\"';
                    // объект может быть entity или данное, у данного может быть языковый спецификатор или тип
                    if (isDatatype)
                    {
                        g.Assert(new Triple(g.CreateUriNode(subject),
                                            g.CreateUriNode(predicate), g.CreateLiteralNode(rest_line)));
                    }
                    else
                    { // entity
                        string entity = rest_line[0] == '<' ? rest_line.Substring(1, rest_line.Length - 2) : GetEntityString(g, rest_line);
                        g.Assert(new Triple(g.CreateUriNode(subject),
                                            g.CreateUriNode(predicate), g.CreateUriNode(entity)));
                    }
                    ntriples++;
                }
            }
            g.Build();
        }