示例#1
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);
        }