Exemplo n.º 1
0
        public void ExecuteGQL(String myQuery, Dictionary <String, String> myParams)
        {
            IQueryResult _QueryResult = null;

            try
            {
                var transactionID = _GraphDS.BeginTransaction(null);

                _QueryResult = _GraphDS.Query(null, transactionID, myQuery, "sones.gql");

                GenerateResultOutput(_QueryResult, myParams);

                _GraphDS.CommitTransaction(null, transactionID);
            }
            catch (Exception ex)
            {
                if (ex.Message != null)
                {
                    _ErrorMsg.Error400_BadRequest(ex.Message + ex.StackTrace);
                }
                else
                {
                    _ErrorMsg.Error400_BadRequest("Error from " + ex.Source + ex.StackTrace);
                }
            }
        }
Exemplo n.º 2
0
        public void Execute(IGraphDS myGraphDS, long myIterations, Converter.WriteLineToConsole MyWriteLine)
        {
            var transactionID = myGraphDS.BeginTransaction(null);

            var vertexType = myGraphDS.GetVertexType<IVertexType>(null, transactionID, new RequestGetVertexType("City"), (stats, vType) => vType);
            var inCountryProperty = vertexType.GetOutgoingEdgeDefinition("InCountry");
            var nameProperty = vertexType.GetPropertyDefinition("Name");

            List<double> timeForCityCountryTraversal = new List<double>();

            for (int i = 0; i < myIterations; i++)
            {
                Stopwatch sw = Stopwatch.StartNew();

                foreach (var aCity in myGraphDS.GetVertices<IEnumerable<IVertex>>(null, transactionID, new RequestGetVertices("City"), (stats, v) => v))
                {
                    var UK_Vertex = aCity.GetOutgoingSingleEdge(inCountryProperty.ID).GetTargetVertex();
                }

                sw.Stop();

                timeForCityCountryTraversal.Add(sw.Elapsed.TotalMilliseconds);
            }

            myGraphDS.CommitTransaction(null, transactionID);

            String result =  GenerateTable(timeForCityCountryTraversal) + Environment.NewLine + String.Format("Average: {0}ms Median: {1}ms StandardDeviation {2}ms ", Statistics.Average(timeForCityCountryTraversal), Statistics.Median(timeForCityCountryTraversal), Statistics.StandardDeviation(timeForCityCountryTraversal));
            Console.WriteLine(result);

            MyWriteLine(result);
        }
Exemplo n.º 3
0
        public void SocialNetwork(IGraphDS myGraphDS)
        {
            var transactionID = myGraphDS.BeginTransaction(null);

            #region ontology [API]

            var entityTypeDefinition = new VertexTypePredefinition(_vtEntity)
                        .AddProperty(new PropertyPredefinition(_pName, typeof(String).Name));

            var userTypeDefinition =
                new VertexTypePredefinition(_vtUser)
                        .SetSuperTypeName(_vtEntity)
                        .AddOutgoingEdge(new OutgoingEdgePredefinition(_pHasVisited, _vtCity).SetMultiplicityAsMultiEdge());

            var placeTypeDefinition =
                new VertexTypePredefinition(_vtPlace)
                        .SetSuperTypeName(_vtEntity);

            var countryTypeDefinition =
                new VertexTypePredefinition(_vtCountry)
                        .SetSuperTypeName(_vtPlace)
                        .AddIncomingEdge(new IncomingEdgePredefinition(_pCities, _vtCity, _pInCountry));

            var cityTypeDefinition =
                new VertexTypePredefinition(_vtCity)
                        .SetSuperTypeName(_vtPlace)
                        .AddOutgoingEdge(new OutgoingEdgePredefinition(_pInCountry, _vtCountry));

            Dictionary<String, IVertexType> vertexTypes = myGraphDS.CreateVertexTypes(null, transactionID,
                new RequestCreateVertexTypes(new List<VertexTypePredefinition>
                    { 	entityTypeDefinition,
                        userTypeDefinition,
                        placeTypeDefinition,
                        countryTypeDefinition,
                        cityTypeDefinition
                    }),
                (stats, types) => types.ToDictionary(vType => vType.Name, vType => vType));

            #endregion

            #region country [GQL]
            ExecuteQuery("insert into " + _vtCountry + " values ( " + _pName + " = 'UK' )", myGraphDS, transactionID);

            #endregion

            #region cities [GQL]

            var cityVertexIDs = new List<long>();
            foreach (var aCity in new List<String> { "London", "Manchester", "Edinburgh", "Cambridge", "Oxford" })
            {
                cityVertexIDs.Add(ExecuteQuery("insert into " + _vtCity + " values ( " + _pName + " = '" + aCity + "', " + _pInCountry + " = REF(" + _pName + " = 'UK'))", myGraphDS, transactionID).First().GetProperty<long>("VertexID"));
            }

            #endregion

            #region user [API]

            var userType = vertexTypes[_vtUser];
            var cityType = vertexTypes[_vtCity];

            Parallel.ForEach(
                Partitioner.Create(0, _countOfUsers, _countOfUsers / Environment.ProcessorCount),
                range =>
                {
                    for (long i = range.Item1; i < range.Item2; i++)
                    {
                        CreateANewUser(userType, i, myGraphDS, cityVertexIDs, cityType, transactionID);
                    }
                });

            #endregion

            myGraphDS.CommitTransaction(null, transactionID);
        }
Exemplo n.º 4
0
        public void Execute(IGraphDS myGraphDS, long myIterations, Converter.WriteLineToConsole MyWriteLine)
        {
            var transactionID = myGraphDS.BeginTransaction(null);

            var vertexType = myGraphDS.GetVertexType<IVertexType>(null, transactionID, new RequestGetVertexType(_interestingVertexType), (stats, vType) => vType);
            var vertices = myGraphDS.GetVertices<IEnumerable<IVertex>>(null, transactionID, new RequestGetVertices(_interestingVertexType), (stats, v) => v);
            Stopwatch sw = Stopwatch.StartNew();

            for (int i = 0; i < myIterations - 1; i++)
            {
                CountAllEdgesParallel(vertices);
            }

            var edgeCount = CountAllEdgesParallel(vertices);

            sw.Stop();

            myGraphDS.CommitTransaction(null, transactionID);

            MyWriteLine(String.Format("Counted {0} edges.", edgeCount));

            MyWriteLine(String.Format("Traversed {0} edges per second", edgeCount / (sw.Elapsed.TotalSeconds / myIterations)));
        }
Exemplo n.º 5
0
        public void SocialNetwork(IGraphDS myGraphDS)
        {
            Random PRNG = new Random();
            List<long> vertexIDs = new List<long>();

            var transactionID = myGraphDS.BeginTransaction(null);

            //create the user type
            var usertype = myGraphDS.CreateVertexType<IVertexType>(null, transactionID,
                new RequestCreateVertexType(
                    new VertexTypePredefinition("User")
                        .AddProperty(new PropertyPredefinition("Name", "String"))
                        .AddProperty(new PropertyPredefinition("Age", "Int32"))
                        .AddIndex(new IndexPredefinition("MyAgeIndex").SetIndexType("sonesindex").AddProperty("Age").SetVertexType("User"))
                        .AddOutgoingEdge(new OutgoingEdgePredefinition("Friends", "User").SetMultiplicityAsMultiEdge())
                ),
                (stats, vType) => vType);

            Console.Write("Imported User: ");

            for (long i = 0; i < _countOfUsers; i++)
            {
                if (i % 1000 == 0)
                {
                    String iString = i.ToString();
                    Console.Write(iString);
                    Console.CursorLeft -= iString.Length;
                }

                vertexIDs.Add(CreateANewUser(usertype, i, vertexIDs, PRNG, myGraphDS, transactionID));
            }
        }
Exemplo n.º 6
0
        public void Execute(IGraphDS myGraphDS, long myIterations, Converter.WriteLineToConsole MyWriteLine)
        {
            var transactionID = myGraphDS.BeginTransaction(null);

            var vertexType = myGraphDS.GetVertexType<IVertexType>(null, transactionID, new RequestGetVertexType(_interestingVertexType), (stats, vType) => vType);
            var vertexList = myGraphDS.GetVertices<List<IVertex>>(null, transactionID, new RequestGetVertices(_interestingVertexType), (stats, vertices) => vertices.ToList());
            List<double> tps = new List<double>();
            long edgeCount= 0;

            for (int i = 0; i < myIterations; i++)
            {
                Stopwatch sw = Stopwatch.StartNew();

                edgeCount = CountAllEdgesParallelPartitioner(vertexType, myGraphDS, vertexList);

                sw.Stop();

                tps.Add(edgeCount / sw.Elapsed.TotalSeconds);
            }

            myGraphDS.CommitTransaction(null, transactionID);

            MyWriteLine(String.Format("Traversed {0} edges.", edgeCount));

            MyWriteLine(String.Format("Traversed {0} edges. Average: {1}TPS Median: {2}TPS StandardDeviation {3}TPS ", edgeCount, Statistics.Average(tps), Statistics.Median(tps), Statistics.StandardDeviation(tps)));
        }
Exemplo n.º 7
0
        public TagExample()
        {
            //Make a new GraphDB instance
            GraphDB = new SonesGraphDB();

            #region Configure PlugIns
            // Plugins are loaded by the GraphDS with their according PluginDefinition and only if they are listed
            // below - there is no auto-discovery for plugin types in GraphDS (!)

            #region Query Languages
            // the GQL Query Language Plugin needs the GraphDB instance as a parameter
            List<PluginDefinition> QueryLanguages = new List<PluginDefinition>();
            Dictionary<string, object> GQL_Parameters = new Dictionary<string, object>();
            GQL_Parameters.Add("GraphDB", GraphDB);

            QueryLanguages.Add(new PluginDefinition("sones.gql", GQL_Parameters));
            #endregion

            #endregion

            GraphDSPlugins PluginsAndParameters = new GraphDSPlugins(null, QueryLanguages);

            var credentials = new UserPasswordCredentials("User", "test");

            GraphDSServer = new GraphDS_Server(GraphDB, (ushort)9975, "User", "test", IPAddress.Any, PluginsAndParameters);
            GraphDSServer.LogOn(credentials);
            //GraphDSServer.StartRESTService("", Properties.Settings.Default.ListeningPort, IPAddress.Any);

            //get a Security- and TransactionToken
            SecToken = GraphDSServer.LogOn(credentials);
            TransToken = GraphDSServer.BeginTransaction(SecToken);
        }