本文整理汇总了C#中Graph.NewEdgeType方法的典型用法代码示例。如果您正苦于以下问题:C# Graph.NewEdgeType方法的具体用法?C# Graph.NewEdgeType怎么用?C# Graph.NewEdgeType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Graph
的用法示例。
在下文中一共展示了Graph.NewEdgeType方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateGraph
static readonly string s_licenseDbFile = "c:/4.odb"; // (download from https://www.velocitydb.com/Secure/Download.aspx)
static void CreateGraph()
{
using (SessionNoServer session = new SessionNoServer(systemDir))
{
if (Directory.Exists(session.SystemDirectory))
Directory.Delete(session.SystemDirectory, true); // remove systemDir from prior runs and all its databases.
// Start an update transaction
session.BeginUpdate();
// Copy VelocityDB license database to this database directory
File.Copy(s_licenseDbFile, Path.Combine(session.SystemDirectory, "4.odb"));
Graph g = new Graph(session);
session.Persist(g);
// Add a node type for the movies, with a unique identifier and two indexed Propertys
VertexType movieType = g.NewVertexType("Movie");
PropertyType movieTitleType = g.NewVertexProperty(movieType, "title", DataType.String, PropertyKind.Indexed);
PropertyType movieYearType = g.NewVertexProperty(movieType, "year", DataType.Integer, PropertyKind.Indexed);
// Add a node type for the actor
VertexType actorType = g.NewVertexType("Actor");
PropertyType actorNameType = g.NewVertexProperty(actorType, "name", DataType.String, PropertyKind.Indexed);
// Add a directed edge type with a Property for the cast of a movie
EdgeType castType = g.NewEdgeType("ACTS_IN", false);
PropertyType castCharacterType = g.NewEdgeProperty(castType, "role", DataType.String, PropertyKind.Indexed);
// Add some Movies
Vertex matrix1 = movieType.NewVertex();
matrix1.SetProperty(movieTitleType, "The Matrix");
matrix1.SetProperty(movieYearType, (int)1999);
Vertex matrix2 = movieType.NewVertex();
matrix2.SetProperty(movieTitleType, "The Matrix Reloaded");
matrix2.SetProperty(movieYearType, (int)2003);
Vertex matrix3 = movieType.NewVertex();
matrix3.SetProperty(movieTitleType, "The Matrix Revolutions");
matrix3.SetProperty(movieYearType, (int)2003);
// Add some Actors
Vertex keanu = actorType.NewVertex();
keanu.SetProperty(actorNameType, "Keanu Reeves");
Vertex laurence = actorType.NewVertex();
laurence.SetProperty(actorNameType, "Laurence Fishburne");
Vertex carrieanne = actorType.NewVertex();
carrieanne.SetProperty(actorNameType, "Carrie-Anne Moss");
// Add some edges
Edge keanuAsNeo = castType.NewEdge(keanu, matrix1);
keanuAsNeo.SetProperty(castCharacterType, "Neo");
keanuAsNeo = castType.NewEdge(keanu, matrix2);
keanuAsNeo.SetProperty(castCharacterType, "Neo");
keanuAsNeo = castType.NewEdge(keanu, matrix3);
keanuAsNeo.SetProperty(castCharacterType, "Neo");
Edge laurenceAsMorpheus = castType.NewEdge(laurence, matrix1);
laurenceAsMorpheus.SetProperty(castCharacterType, "Morpheus");
laurenceAsMorpheus = castType.NewEdge(laurence, matrix2);
laurenceAsMorpheus.SetProperty(castCharacterType, "Morpheus");
laurenceAsMorpheus = castType.NewEdge(laurence, matrix3);
laurenceAsMorpheus.SetProperty(castCharacterType, "Morpheus");
Edge carrieanneAsTrinity = castType.NewEdge(carrieanne, matrix1);
carrieanneAsTrinity.SetProperty(castCharacterType, "Trinity");
carrieanneAsTrinity = castType.NewEdge(carrieanne, matrix2);
carrieanneAsTrinity.SetProperty(castCharacterType, "Trinity");
carrieanneAsTrinity = castType.NewEdge(carrieanne, matrix3);
carrieanneAsTrinity.SetProperty(castCharacterType, "Trinity");
// Commit the transaction
session.Commit();
}
}
示例2: ingestData
public void ingestData()
{
if (Directory.Exists(Path.Combine(SessionBase.BaseDatabasePath, s_systemDir)))
Directory.Delete(Path.Combine(SessionBase.BaseDatabasePath, s_systemDir), true); // remove systemDir from prior runs and all its databases.
Directory.CreateDirectory(Path.Combine(SessionBase.BaseDatabasePath, s_systemDir));
File.Copy(s_licenseDbFile, Path.Combine(SessionBase.BaseDatabasePath, s_systemDir, "4.odb"));
using (SessionNoServer session = new SessionNoServer(s_systemDir, 5000, false, true))
{
session.BeginUpdate();
session.DefaultDatabaseLocation().CompressPages = PageInfo.compressionKind.LZ4;
Graph g = new Graph(session);
// SCHEMA
VertexType userType = g.NewVertexType("User");
EdgeType friendEdgeType = g.NewEdgeType("Friend", true, userType, userType);
PropertyType countryProperty = userType.NewProperty("country", DataType.String, PropertyKind.NotIndexed);
PropertyType incomeProperty = userType.NewProperty("income", DataType.Long, PropertyKind.NotIndexed);
PropertyType friendshipStartProperty = friendEdgeType.NewProperty("start", DataType.DateTime, PropertyKind.NotIndexed);
// DATA
int lineNumber = 0;
long fiendsCt = 0;
int stop = (int)Math.Pow(2, 26); // make sure to create enough of these
for (int i = 1; i < stop; i++)
g.NewVertex(userType);
session.Commit();
session.BeginUpdate();
foreach (string line in File.ReadLines(s_inputData))
{
if (++lineNumber % 10000 == 0)
Console.WriteLine("Parsing user " + lineNumber + ", friends total: " + fiendsCt + " at " + DateTime.Now);
string[] fields = line.Split(' ');
Vertex aUser = null;
foreach (string s in fields)
{
if (s.Length > 0)
{
if (aUser == null)
aUser = new Vertex(g, userType, int.Parse(s));
else
{
++fiendsCt;
Vertex aFriend = new Vertex(g, userType, int.Parse(s));
if (fiendsCt % 2 == 0)
aFriend.SetProperty(countryProperty, "Sweden"); // just some random stuff
else
aFriend.SetProperty(incomeProperty, fiendsCt); // just some random stuff
Edge edge = friendEdgeType.NewEdge(aUser, aFriend);
if (fiendsCt % 2 == 0)
edge.SetProperty(friendshipStartProperty, DateTime.Now);
}
}
}
if (DataCache.MaximumMemoryUse <= 27000000000)
{
if (lineNumber >= 20000) // remove this condition if you have time to wait a long while...
break;
}
}
Console.WriteLine("Done importing " + lineNumber + " users with " + fiendsCt + " friends");
session.Commit();
}
}
示例3: Main
static int Main(string[] args)
{
DataCache.MaximumMemoryUse = 10000000000; // 10 GB, set this to what fits your case
SupplierTracking supplierTracking = new SupplierTracking();
using (SessionNoServer session = new SessionNoServer(s_systemDir, 5000, false, true))
{
if (Directory.Exists(session.SystemDirectory))
Directory.Delete(session.SystemDirectory, true); // remove systemDir from prior runs and all its databases.
Directory.CreateDirectory(session.SystemDirectory);
File.Copy(s_licenseDbFile, Path.Combine(session.SystemDirectory, "4.odb"));
session.BeginUpdate();
Graph g = new Graph(session, false);
// SCHEMA
VertexType warehouseVertexType = g.NewVertexType("Warehouse");
VertexType supplierVertexType = g.NewVertexType("Supplier");
EdgeType supplierWarehouseEdgeType = g.NewEdgeType("Warehouse", true, supplierVertexType, warehouseVertexType);
EdgeType moveToS1EdgeType = g.NewEdgeType("MoveS1To", true, warehouseVertexType, warehouseVertexType);
EdgeType moveToS2EdgeType = g.NewEdgeType("MoveS2To", true, warehouseVertexType, warehouseVertexType);
EdgeType moveToS3EdgeType = g.NewEdgeType("MoveS3To", true, warehouseVertexType, warehouseVertexType);
PropertyType supplierNameProperty = supplierVertexType.NewProperty("name", DataType.String, PropertyKind.NotIndexed);
PropertyType wareHouseNameProperty = warehouseVertexType.NewProperty("name", DataType.String, PropertyKind.NotIndexed);
PropertyType howManyS1Property = moveToS1EdgeType.NewProperty("howMany", DataType.Integer, PropertyKind.NotIndexed);
PropertyType howManyS2Property = moveToS2EdgeType.NewProperty("howMany", DataType.Integer, PropertyKind.NotIndexed);
PropertyType howManyS3Property = moveToS3EdgeType.NewProperty("howMany", DataType.Integer, PropertyKind.NotIndexed);
Vertex supplier1 = supplierVertexType.NewVertex();
supplier1.SetProperty(supplierNameProperty, "S1");
Vertex supplier2 = supplierVertexType.NewVertex();
supplier2.SetProperty(supplierNameProperty, "S2");
Vertex supplier3 = supplierVertexType.NewVertex();
supplier3.SetProperty(supplierNameProperty, "S3");
Vertex wareHouse1Supplier1 = warehouseVertexType.NewVertex();
supplier1.AddEdge(supplierWarehouseEdgeType, wareHouse1Supplier1);
wareHouse1Supplier1.SetProperty(wareHouseNameProperty, "A01");
Vertex wareHouse2Supplier1 = warehouseVertexType.NewVertex();
supplier1.AddEdge(supplierWarehouseEdgeType, wareHouse2Supplier1);
wareHouse2Supplier1.SetProperty(wareHouseNameProperty, "A02");
Vertex wareHouse3Supplier1 = warehouseVertexType.NewVertex();
supplier1.AddEdge(supplierWarehouseEdgeType, wareHouse3Supplier1);
wareHouse3Supplier1.SetProperty(wareHouseNameProperty, "A05");
Vertex wareHouse4Supplier1 = warehouseVertexType.NewVertex();
supplier1.AddEdge(supplierWarehouseEdgeType, wareHouse4Supplier1);
wareHouse4Supplier1.SetProperty(wareHouseNameProperty, "A06");
Vertex wareHouse1Supplier2 = warehouseVertexType.NewVertex();
supplier2.AddEdge(supplierWarehouseEdgeType, wareHouse1Supplier2);
wareHouse1Supplier2.SetProperty(wareHouseNameProperty, "A03");
Vertex wareHouse2Supplier2 = warehouseVertexType.NewVertex();
supplier2.AddEdge(supplierWarehouseEdgeType, wareHouse2Supplier2);
wareHouse2Supplier2.SetProperty(wareHouseNameProperty, "A07");
Vertex wareHouse1Supplier3 = warehouseVertexType.NewVertex();
supplier3.AddEdge(supplierWarehouseEdgeType, wareHouse1Supplier3);
wareHouse1Supplier3.SetProperty(wareHouseNameProperty, "A04");
Vertex wareHouse2Supplier3 = warehouseVertexType.NewVertex();
supplier3.AddEdge(supplierWarehouseEdgeType, wareHouse2Supplier3);
wareHouse2Supplier3.SetProperty(wareHouseNameProperty, "A08");
Vertex wareHouseB1 = warehouseVertexType.NewVertex();
wareHouseB1.SetProperty(wareHouseNameProperty, "B01");
Vertex wareHouseB2 = warehouseVertexType.NewVertex();
wareHouseB2.SetProperty(wareHouseNameProperty, "B02");
Vertex wareHouseB3 = warehouseVertexType.NewVertex();
wareHouseB3.SetProperty(wareHouseNameProperty, "B03");
Vertex wareHouseB4 = warehouseVertexType.NewVertex();
wareHouseB4.SetProperty(wareHouseNameProperty, "B04");
Vertex wareHouseC1 = warehouseVertexType.NewVertex();
wareHouseC1.SetProperty(wareHouseNameProperty, "C01");
Vertex wareHouseC2 = warehouseVertexType.NewVertex();
wareHouseC2.SetProperty(wareHouseNameProperty, "C02");
Vertex wareHouseD1 = warehouseVertexType.NewVertex();
wareHouseD1.SetProperty(wareHouseNameProperty, "D01");
Edge moveA1toB1 = wareHouse1Supplier1.AddEdge(moveToS1EdgeType, wareHouseB1);
moveA1toB1.SetProperty(howManyS1Property, 750);
Edge moveA2toB1 = wareHouse2Supplier1.AddEdge(moveToS1EdgeType, wareHouseB1);
moveA2toB1.SetProperty(howManyS1Property, 500);
Edge moveA3toB2 = wareHouse1Supplier2.AddEdge(moveToS2EdgeType, wareHouseB2);
moveA3toB2.SetProperty(howManyS2Property, 750);
Edge moveA4toB2 = wareHouse1Supplier3.AddEdge(moveToS3EdgeType, wareHouseB2);
moveA4toB2.SetProperty(howManyS3Property, 500);
Edge moveA5toB3 = wareHouse3Supplier1.AddEdge(moveToS1EdgeType, wareHouseB3);
moveA5toB3.SetProperty(howManyS1Property, 100);
Edge moveA6toB3 = wareHouse4Supplier1.AddEdge(moveToS1EdgeType, wareHouseB3);
moveA6toB3.SetProperty(howManyS1Property, 200);
Edge moveA7toB4 = wareHouse2Supplier2.AddEdge(moveToS2EdgeType, wareHouseB4);
moveA7toB4.SetProperty(howManyS2Property, 50);
Edge moveA8toB4 = wareHouse2Supplier3.AddEdge(moveToS3EdgeType, wareHouseB4);
//.........这里部分代码省略.........
示例4: Main
static void Main(string[] args)
{
bool import = args.Length > 0 && args[0].ToLower() == "-import";
bool dirExist = Directory.Exists(s_systemDir);
if (import || !dirExist)
{
if (dirExist)
Directory.Delete(s_systemDir, true); // remove systemDir from prior runs and all its databases.
Directory.CreateDirectory(s_systemDir);
File.Copy(s_licenseDbFile, Path.Combine(s_systemDir, "4.odb"));
using (SessionNoServer session = new SessionNoServer(s_systemDir))
{
DataCache.MaximumMemoryUse = 10000000000; // 10 GB, set this to what fits your case
session.BeginUpdate();
session.DefaultDatabaseLocation().CompressPages = PageInfo.compressionKind.LZ4;
Graph g = new Graph(session);
session.Persist(g);
// SCHEMA
VertexType userType = g.NewVertexType("User");
PropertyType genderType = userType.NewProperty("Gender", DataType.Integer, PropertyKind.Indexed);
VertexType ratingType = g.NewVertexType("Rating");
PropertyType ratingValuePropertyType = ratingType.NewProperty("RatingValue", DataType.Integer, PropertyKind.Indexed);
EdgeType ratingEdgeType = g.NewEdgeType("UserToRating", true, userType, ratingType);
EdgeType ratingOfType = g.NewEdgeType("RatingOf", false, userType, userType);
PropertyType ratingEdgePropertyType = ratingOfType.NewProperty("Rating", DataType.Integer, PropertyKind.Indexed);
// DATA
using (FileStream stream = File.OpenRead(System.IO.Path.Combine(s_inputDataDir, "gender.dat")))
{
using (StreamReader file = new System.IO.StreamReader(stream))
{
string line;
int lineNumber = 0;
while ((line = file.ReadLine()) != null)
{
lineNumber++;
string[] fields = line.Split(',');
Vertex aUser = userType.NewVertex();
aUser.SetProperty(genderType, (int)fields[1][0] == 'M' ? Gender.Male : fields[1][0] == 'F' ? Gender.Female : Gender.Unknown);
}
Console.WriteLine("Done importing " + lineNumber + " users");
}
}
using (FileStream stream = File.OpenRead(System.IO.Path.Combine(s_inputDataDir, "ratings.dat")))
{
using (StreamReader file = new System.IO.StreamReader(stream))
{
string line;
int lineNumber = 0;
Vertex rater = null;
int raterId;
int priorRaterId = -1;
while ((line = file.ReadLine()) != null)
{
lineNumber++;
if (lineNumber % 1000000 == 0)
Console.WriteLine("Parsing rating # " + lineNumber);
string[] fields = line.Split(',');
raterId = int.Parse(fields[0]);
if (raterId != priorRaterId)
rater = userType.GetVertex(raterId);
priorRaterId = raterId;
int ratedId = int.Parse(fields[1]);
int rating = int.Parse(fields[2]);
Vertex ratingVertex = (from v in ratingType.GetVertices() where ((int)v.GetProperty(ratingValuePropertyType)) == rating select v).FirstOrDefault();
if (ratingVertex == null)
{
ratingVertex = ratingType.NewVertex();
ratingVertex.SetProperty(ratingValuePropertyType, rating);
}
Vertex rated = userType.GetVertex(ratedId);
Edge aRatingOf = ratingOfType.NewEdge(rater, rated);
aRatingOf.SetProperty(ratingEdgePropertyType, rating);
Edge userRating = ratingEdgeType.NewEdge(rated, ratingVertex);
if (lineNumber >= 10000000) // remove this condition if you have time to wait a while and you have at least 16GB of RAM memory
break;
}
Console.WriteLine("Done importing " + lineNumber + " ratings");
}
}
session.Commit();
}
}
// Query
using (SessionNoServer session = new SessionNoServer(s_systemDir))
{
session.BeginRead();
Graph g = Graph.Open(session);
VertexType userType = g.FindVertexType("User");
PropertyType genderType = userType.FindProperty("Gender");
VertexType ratingType = g.FindVertexType("Rating");
PropertyType ratingValuePropertyType = ratingType.FindProperty("RatingValue");
//.........这里部分代码省略.........
示例5: AddVertices
public void AddVertices()
{
using (var session = new SessionNoServer(@"d:\graphtest2"))
{
session.DefaultDatabaseLocation().CompressPages = PageInfo.compressionKind.LZ4;
DataCache.MaximumMemoryUse = 4000000000;
var sw = new Stopwatch();
sw.Start();
//int i = 0;
//var dbl = new DatabaseLocation(Dns.GetHostEntry("wordanalysis.cloudapp.net").HostName, @"Z:\DBStore\", 0,
// 3, session);
//DatabaseLocation bl = session.NewLocation(dbl);
//session.Commit(false);
// Assert.That(bl!=null);
// var db = session.OpenDatabase(15, true);
session.BeginUpdate();
var graph = new Graph(session);
//define schema Trace.Wri
VertexType concept = graph.NewVertexType("Concept");
PropertyType conceptName = concept.NewProperty("ConceptName", DataType.String, PropertyKind.Unique);
PropertyType conceptSize = concept.NewProperty("ConceptSize", DataType.Integer, PropertyKind.NotIndexed);
PropertyType conceptFrequency = concept.NewProperty("ConceptFrequency", DataType.Integer, PropertyKind.NotIndexed);
PropertyType similarity = concept.NewProperty("Similarity", DataType.Double, PropertyKind.NotIndexed);
PropertyType vagueness = concept.NewProperty("Vagueness", DataType.Double, PropertyKind.NotIndexed);
VertexType instance = graph.NewVertexType("Instance", concept);
PropertyType instanceSize = instance.NewProperty("InstanceSize", DataType.Integer,
PropertyKind.NotIndexed);
PropertyType instanceName = instance.NewProperty("InstanceName", DataType.String,
PropertyKind.Unique);
PropertyType instanceFrequency = instance.NewProperty("InstanceFrequency",
DataType.Integer,
PropertyKind.NotIndexed);
//VertexType attributes = graph.NewVertexType("Attribute");
////EdgeType hasAttirbute = attributes.edgattributes.NewHeadToTailEdge(nameScorePair,);
//EdgeType cooccursWith = graph.NewEdgeType("CooccursWith", true, instance, instance);
//PropertyType coocurrenceFrequency = namedScore.NewProperty("IntScore", DataType.Integer,
// PropertyKind.NotIndexed);
//VertexType synonym = graph.NewVertexType("Synonym", namedScore);
//PropertyType synonymScore = synonym.NewProperty("Score", DataType.Integer, PropertyKind.NotIndexed);
//EdgeType hasSynonym = graph.NewEdgeType("HasSynonym", true, synonym, instance);
EdgeType isA = graph.NewEdgeType("IsA", true, concept, instance);
PropertyType frequency = isA.NewProperty("frequency", DataType.Integer, PropertyKind.NotIndexed);
PropertyType popularity = isA.NewProperty("popularity", DataType.Integer, PropertyKind.NotIndexed);
PropertyType ZipfSlope = isA.NewProperty("zipf_slope", DataType.Double, PropertyKind.NotIndexed);
PropertyType ZipfPearson = isA.NewProperty("zipf_pearson", DataType.Double, PropertyKind.NotIndexed);
EdgeType cooccurence = graph.NewEdgeType("Coocurrence", true, concept, concept);
//LRVertex vx1 = graph.NewVertex(instance);
//vx1.SetProperty("Name", "bla");
//LRVertex vx2 = graph.NewVertex(instance);
//vx2.SetProperty("bla", "name");
//LREdge edge = graph.NewEdge(cooccurence, vx1, vx2);
Vertex v2 = graph.NewVertex(concept);
v2.SetProperty(conceptName, "factor");
Vertex v3 = graph.NewVertex(instance);
v3.SetProperty(instanceName, "age");
session.Commit();
}
using (var session = new SessionNoServer(@"d:\graphtest2"))
{
//session.DefaultDatabaseLocation().CompressPages = true;
DataCache.MaximumMemoryUse = 4000000000;
var sw = new Stopwatch();
sw.Start();
//int i = 0;
session.BeginRead();
var graph = Graph.Open(session);
//define schema Trace.Wri
var vertexTypes = graph.FindVertexTypes();
//vertexTypes.Select(x => x.TypeName).PrintDump();
var edgeTypes = graph.FindEdgeTypes();
VertexType concept = vertexTypes.FirstOrDefault(x => x.TypeName == "Concept") ?? graph.NewVertexType("Concept");
PropertyType conceptName = concept.FindProperty("ConceptName");
Assert.IsNotNull(conceptName, "ConceptName");
PropertyType conceptSize = concept.FindProperty("ConceptSize");
Assert.IsNotNull(conceptSize, "ConceptSize");
PropertyType conceptFrequency = concept.FindProperty("ConceptFrequency");
//.........这里部分代码省略.........
示例6: TestVelecoityBuildLocal
// [Test]
public void TestVelecoityBuildLocal()
{
using (var session = new SessionNoServer(@"d:\graphtest"))
{
session.BeginUpdate();
session.DefaultDatabaseLocation().CompressPages = PageInfo.compressionKind.LZ4;
DataCache.MaximumMemoryUse = 2000000000;
//var dbl = new DatabaseLocation(Dns.GetHostEntry("wordanalysis.cloudapp.net").HostName, @"Z:\DBStore\", 0,
// 3, session);
//DatabaseLocation bl = session.NewLocation(dbl);
//session.Commit(false);
// Assert.That(bl!=null);
var graph = new Graph(session);
session.Persist(graph);
//define schema
// session.BeginUpdate();
VertexType namedScore = graph.NewVertexType("NamedScore");
PropertyType name = namedScore.NewProperty("Name", DataType.String, PropertyKind.Indexed);
PropertyType int_score = namedScore.NewProperty("IntScore", DataType.Integer,
PropertyKind.NotIndexed);
PropertyType double_score = namedScore.NewProperty("DoubleScore", DataType.Double,
PropertyKind.NotIndexed);
VertexType concept = graph.NewVertexType("Concept");
PropertyType conceptName = concept.NewProperty("Name", DataType.String, PropertyKind.Unique);
PropertyType conceptSize = concept.NewProperty("ConceptSize", DataType.Integer, PropertyKind.NotIndexed);
PropertyType conceptFrequency = concept.NewProperty("ConceptFrequency", DataType.Integer, PropertyKind.NotIndexed);
PropertyType similarity = concept.NewProperty("Similarity", DataType.Double, PropertyKind.NotIndexed);
PropertyType vagueness = concept.NewProperty("Vagueness", DataType.Double, PropertyKind.NotIndexed);
VertexType instance = graph.NewVertexType("Instance", concept);
PropertyType instanceSize = instance.NewProperty("InstanceSize", DataType.Integer, PropertyKind.NotIndexed);
PropertyType instanceFrequency = instance.NewProperty("InstanceFrequency", DataType.Integer, PropertyKind.NotIndexed);
PropertyType instanceName = instance.NewProperty("Name", DataType.String, PropertyKind.Unique);
VertexType attributes = graph.NewVertexType("Attribute", namedScore);
//EdgeType hasAttirbute = attributes.edgattributes.NewHeadToTailEdge(nameScorePair,);
EdgeType cooccursWith = graph.NewEdgeType("CooccursWith", true, instance, instance);
PropertyType coocurrenceFrequency = namedScore.NewProperty("IntScore", DataType.Integer, PropertyKind.NotIndexed);
VertexType synonym = graph.NewVertexType("Synonym", namedScore);
PropertyType synonymScore = synonym.NewProperty("Score", DataType.Integer, PropertyKind.NotIndexed);
EdgeType hasSynonym = graph.NewEdgeType("HasSynonym", true, synonym, instance);
EdgeType isA = graph.NewEdgeType("IsA", true, concept, instance);
PropertyType frequency = isA.NewProperty("frequency", DataType.Integer, PropertyKind.NotIndexed);
PropertyType popularity = isA.NewProperty("popularity", DataType.Integer, PropertyKind.NotIndexed);
PropertyType ZipfSlope = isA.NewProperty("zipf_slope", DataType.Double, PropertyKind.NotIndexed);
PropertyType ZipfPearson = isA.NewProperty("zipf_pearson", DataType.Double, PropertyKind.NotIndexed);
EdgeType cooccurence = graph.NewEdgeType("Coocurrence", true, concept, concept);
//Vertex vx1 = graph.NewVertex(instance);
//vx1.SetProperty("Name", "bla");
//Vertex vx2 = graph.NewVertex(instance);
//vx2.SetProperty("bla", "name");
//Edge edge = graph.NewEdge(cooccurence, vx1, vx2);
using (var llz = new StreamReader(@"d:\isa_core.txt"))
{
string lastConcept = string.Empty;
while (!llz.EndOfStream)
{
string ln = llz.ReadLine();
if (string.IsNullOrEmpty(ln)) continue;
string[] items = ln.Split(new[] { '\t' });
if (items.Length < 4) continue;
int id = -1;
if (!int.TryParse(items[2], out id)) continue;
var conceptVertex = graph.FindVertex(conceptName, items[0], false);
if (conceptVertex == null)
{
conceptVertex = graph.NewVertex(concept);
conceptVertex.SetProperty(conceptName, items[0]);
conceptVertex.SetProperty(conceptFrequency, int.Parse(items[4]));
conceptVertex.SetProperty(conceptSize, int.Parse(items[5]));
double d = double.NaN;
double.TryParse(items[6], out d);
conceptVertex.SetProperty(vagueness, d);
d = double.NaN;
double.TryParse(items[7], out d);
conceptVertex.SetProperty(ZipfSlope, d);
d = double.NaN;
double.TryParse(items[8], out d);
conceptVertex.SetProperty(ZipfPearson, d);
}
var instanceVertex = graph.FindVertex(instanceName, items[1], false);
if (instanceVertex == null)
{
instanceVertex = graph.NewVertex(instance);
instanceVertex.SetProperty(instanceFrequency, int.Parse(items[9]));
instanceVertex.SetProperty(instanceSize, int.Parse(items[10]));
}
//.........这里部分代码省略.........
示例7: Create1Vertices
public void Create1Vertices(bool vertexIdSetPerVertexType)
{
DataCache.MaximumMemoryUse = 10000000000; // 10 GB
bool dirExist = Directory.Exists(systemDir);
try
{
if (Directory.Exists(systemDir))
Directory.Delete(systemDir, true); // remove systemDir from prior runs and all its databases.
Directory.CreateDirectory(systemDir);
File.Copy(licenseDbFile, Path.Combine(systemDir, "4.odb"));
}
catch
{
File.Copy(licenseDbFile, Path.Combine(systemDir, "4.odb"));
}
using (SessionNoServer session = new SessionNoServer(systemDir, 5000, false, true))
{
session.BeginUpdate();
Graph g = new Graph(session, vertexIdSetPerVertexType);
session.Persist(g);
VertexType userType = g.NewVertexType("User");
VertexType otherType = g.NewVertexType("Other");
PropertyType userNamePropertyType = g.NewVertexProperty(userType, "NAME", DataType.String, PropertyKind.Indexed);
VertexType powerUserType = g.NewVertexType("PowerUser", userType);
EdgeType userFriendEdgeType = g.NewEdgeType("Friend", true, userType, userType);
EdgeType userBestFriendEdgeType = g.NewEdgeType("Best Friend", true, userType, userType, userFriendEdgeType);
EdgeType otherEdgeType = g.NewEdgeType("Other", true, userType, userType);
PropertyType bestFriendPropertyType = g.NewEdgeProperty(userFriendEdgeType, "START", DataType.DateTime, PropertyKind.Indexed);
Vertex kinga = userType.NewVertex();
Vertex robin = userType.NewVertex();
Vertex mats = powerUserType.NewVertex();
Vertex chiran = powerUserType.NewVertex();
Vertex other = otherType.NewVertex();
Edge bestFriend = kinga.AddEdge(userBestFriendEdgeType, robin);
Edge otherEdge = kinga.AddEdge(otherEdgeType, robin);
DateTime now = DateTime.UtcNow;
mats.SetProperty("Address", 1);
bestFriend.SetProperty(bestFriendPropertyType, now);
kinga.SetProperty(userNamePropertyType, "Kinga");
if (g.VertexIdSetPerType == false)
mats.SetProperty(userNamePropertyType, "Mats");
else
{
try
{
mats.SetProperty(userNamePropertyType, "Mats");
Assert.Fail("Invalid property for VertexType not handled");
}
catch (Exception)
{
}
}
try
{
other.SetProperty(userNamePropertyType, "Mats");
Assert.Fail("Invalid property for VertexType not handled");
}
catch (Exception)
{
}
try
{
otherEdge.SetProperty(bestFriendPropertyType, now);
Assert.Fail("Invalid property for VertexType not handled");
}
catch (Exception)
{
}
Vertex findMats = userNamePropertyType.GetPropertyVertex("Mats", true);
var list = userNamePropertyType.GetPropertyVertices("Mats", true).ToList();
//Edge findWhen = bestFriendPropertyType.GetPropertyEdge(now);
//var list2 = bestFriendPropertyType.GetPropertyEdges(now);
Console.WriteLine(findMats);
// session.Commit();
// session.BeginRead();
PropertyType adressProperty = g.FindVertexProperty(powerUserType, "Address");
Vertex find1 = adressProperty.GetPropertyVertex(1, true);
session.Abort();
/*session.BeginUpdate();
g.Unpersist(session);
session.Commit();
dirExist = Directory.Exists(systemDir);
try
{
if (Directory.Exists(systemDir))
Directory.Delete(systemDir, true); // remove systemDir from prior runs and all its databases.
Directory.CreateDirectory(systemDir);
File.Copy(licenseDbFile, Path.Combine(systemDir, "4.odb"));
}
catch
{
File.Copy(licenseDbFile, Path.Combine(systemDir, "4.odb"));
}*/
}
using (SessionNoServer session = new SessionNoServer(systemDir, 5000, false, true))
{
session.BeginUpdate();
//.........这里部分代码省略.........
示例8: TraverseTest
public void TraverseTest()
{
using (SessionNoServer session = new SessionNoServer(systemDir))
{
session.BeginUpdate();
Graph g = new Graph(session);
session.Persist(g);
VertexType Airport_Type = g.NewVertexType("Airport");
PropertyType Airport_Name_Type = g.NewVertexProperty(Airport_Type, "Airport", DataType.String, PropertyKind.Indexed);
VertexType Flight_Type = g.NewVertexType("Flight");
PropertyType Flight_Name_Type = g.NewVertexProperty(Flight_Type, "Flight", DataType.String, PropertyKind.Indexed);
PropertyType Flight_Origin_Type = g.NewVertexProperty(Flight_Type, "Origin", DataType.String, PropertyKind.Indexed);
PropertyType Flight_Dest_Type = g.NewVertexProperty(Flight_Type, "Destination", DataType.String, PropertyKind.Indexed);
EdgeType origin_for = g.NewEdgeType("origin for", true, Airport_Type, Flight_Type);
EdgeType arrives_at = g.NewEdgeType("arrives at", true, Flight_Type, Airport_Type);
Vertex sydney = Airport_Type.NewVertex();
sydney.SetProperty(Airport_Name_Type, "SYD");
Vertex london = Airport_Type.NewVertex();
london.SetProperty(Airport_Name_Type, "LHR");
Vertex madrid = Airport_Type.NewVertex();
madrid.SetProperty(Airport_Name_Type, "MAD");
Vertex dubai = Airport_Type.NewVertex();
dubai.SetProperty(Airport_Name_Type, "DBX");
// sydney to london
Vertex qf1 = Flight_Type.NewVertex();
qf1.SetProperty(Flight_Name_Type, "QF1");
qf1.SetProperty(Flight_Origin_Type, "SYD");
qf1.SetProperty(Flight_Dest_Type, "LHR");
//london to sydney
Vertex qf2 = Flight_Type.NewVertex();
qf2.SetProperty(Flight_Name_Type, "QF2");
qf2.SetProperty(Flight_Origin_Type, "LHR");
qf2.SetProperty(Flight_Dest_Type, "SYD");
//london to madrid
Vertex ba512 = Flight_Type.NewVertex();
ba512.SetProperty(Flight_Name_Type, "BA512");
ba512.SetProperty(Flight_Origin_Type, "LHR");
ba512.SetProperty(Flight_Dest_Type, "MAD");
//madrid to london
Vertex ba461 = Flight_Type.NewVertex();
ba461.SetProperty(Flight_Name_Type, "BA461");
ba461.SetProperty(Flight_Origin_Type, "MAD");
ba461.SetProperty(Flight_Dest_Type, "LHR");
//sydney to dubai
Vertex qf414 = Flight_Type.NewVertex();
qf414.SetProperty(Flight_Name_Type, "QF414");
qf414.SetProperty(Flight_Origin_Type, "SYD");
qf414.SetProperty(Flight_Dest_Type, "DBX");
//dubai to sydney
Vertex qf413 = Flight_Type.NewVertex();
qf413.SetProperty(Flight_Name_Type, "QF413");
qf413.SetProperty(Flight_Origin_Type, "DBX");
qf413.SetProperty(Flight_Dest_Type, "SYD");
//sydney to london
Vertex ba999 = Flight_Type.NewVertex();
ba999.SetProperty(Flight_Name_Type, "BA999");
ba999.SetProperty(Flight_Origin_Type, "SYD");
ba999.SetProperty(Flight_Dest_Type, "LHR");
Vertex ba888 = Flight_Type.NewVertex();
ba888.SetProperty(Flight_Name_Type, "BA888");
ba888.SetProperty(Flight_Origin_Type, "LHR");
ba888.SetProperty(Flight_Dest_Type, "SYD");
Edge anEdge;
anEdge = g.NewEdge(origin_for, sydney, qf1);
anEdge = g.NewEdge(arrives_at, qf1, london);
anEdge = g.NewEdge(origin_for, london, qf2);
anEdge = g.NewEdge(arrives_at, qf2, sydney);
anEdge = g.NewEdge(origin_for, london, ba512);
anEdge = g.NewEdge(arrives_at, ba512, madrid);
anEdge = g.NewEdge(origin_for, madrid, ba461);
anEdge = g.NewEdge(arrives_at, ba461, london);
anEdge = g.NewEdge(origin_for, sydney, qf414);
anEdge = g.NewEdge(arrives_at, qf414, dubai);
anEdge = g.NewEdge(origin_for, dubai, qf413);
anEdge = g.NewEdge(arrives_at, qf413, sydney);
anEdge = g.NewEdge(origin_for, sydney, ba999);
anEdge = g.NewEdge(arrives_at, ba999, london);
//.........这里部分代码省略.........
示例9: Main
static readonly string systemDir = "VelocityGraphSample"; // appended to SessionBase.BaseDatabasePath
static void Main(string[] args)
{
using (SessionNoServer session = new SessionNoServer(systemDir))
{
if (Directory.Exists(session.SystemDirectory))
Directory.Delete(session.SystemDirectory, true); // remove systemDir from prior runs and all its databases.
Console.WriteLine("Running with databases in directory: " + session.SystemDirectory);
session.BeginUpdate();
Graph g = new Graph(session);
session.Persist(g);
// SCHEMA
// Add a node type for the movies, with a unique identifier and two indexed Propertys
VertexType movieType = g.NewVertexType("MOVIE");
PropertyType movieTitleType = g.NewVertexProperty(movieType, "TITLE", DataType.String, PropertyKind.Indexed);
PropertyType movieYearType = g.NewVertexProperty(movieType, "YEAR", DataType.Integer, PropertyKind.Indexed);
// Add a node type for the people, with a unique identifier and an indexed Property
VertexType peopleType = g.NewVertexType("PEOPLE");
PropertyType peopleNameType = g.NewVertexProperty(peopleType, "NAME", DataType.String, PropertyKind.Indexed);
// Add an undirected edge type with a Property for the cast of a movie
EdgeType castType = g.NewEdgeType("CAST", false);
PropertyType castCharacterType = g.NewEdgeProperty(castType, "CHARACTER", DataType.String, PropertyKind.Indexed);
// Add a directed edge type restricted to go from people to movie for the director of a movie
EdgeType directsType = g.NewEdgeType("DIRECTS", true, peopleType, movieType);
// DATA
// Add some MOVIE nodes
Vertex mLostInTranslation = movieType.NewVertex();
mLostInTranslation.SetProperty(movieTitleType, "Lost in Translation");
mLostInTranslation.SetProperty(movieYearType, (int)2003);
Vertex mVickyCB = movieType.NewVertex();
mVickyCB.SetProperty(movieTitleType, "Vicky Cristina Barcelona");
mVickyCB.SetProperty(movieYearType, (int)2008);
Vertex mManhattan = movieType.NewVertex();
mManhattan.SetProperty(movieTitleType, "Manhattan");
mManhattan.SetProperty(movieYearType, (int)1979);
// Add some PEOPLE nodes
Vertex pScarlett = peopleType.NewVertex();
pScarlett.SetProperty(peopleNameType, "Scarlett Johansson");
Vertex pBill = peopleType.NewVertex();
pBill.SetProperty(peopleNameType, "Bill Murray");
Vertex pSofia = peopleType.NewVertex();
pSofia.SetProperty(peopleNameType, "Sofia Coppola");
Vertex pWoody = peopleType.NewVertex();
pWoody.SetProperty(peopleNameType, "Woody Allen");
Vertex pPenelope = peopleType.NewVertex();
pPenelope.SetProperty(peopleNameType, "Penélope Cruz");
Vertex pDiane = peopleType.NewVertex();
pDiane.SetProperty(peopleNameType, "Diane Keaton");
// Add some CAST edges
Edge anEdge;
anEdge = g.NewEdge(castType, mLostInTranslation, pScarlett);
anEdge.SetProperty(castCharacterType, "Charlotte");
anEdge = g.NewEdge(castType, mLostInTranslation, pBill);
anEdge.SetProperty(castCharacterType, "Bob Harris");
anEdge = g.NewEdge(castType, mVickyCB, pScarlett);
anEdge.SetProperty(castCharacterType, "Cristina");
anEdge = g.NewEdge(castType, mVickyCB, pPenelope);
anEdge.SetProperty(castCharacterType, "Maria Elena");
anEdge = g.NewEdge(castType, mManhattan, pDiane);
anEdge.SetProperty(castCharacterType, "Mary");
anEdge = g.NewEdge(castType, mManhattan, pWoody);
anEdge.SetProperty(castCharacterType, "Isaac");
// Add some DIRECTS edges
anEdge = g.NewEdge(directsType, pSofia, mLostInTranslation);
anEdge = g.NewEdge(directsType, pWoody, mVickyCB);
anEdge = g.NewEdge(directsType, pWoody, mManhattan);
// QUERIES
// Get the movies directed by Woody Allen
Dictionary<Vertex, HashSet<Edge>> directedByWoody = pWoody.Traverse(directsType, Direction.Out);
// Get the cast of the movies directed by Woody Allen
Dictionary<Vertex, HashSet<Edge>> castDirectedByWoody = g.Traverse(directedByWoody.Keys.ToArray(), castType, Direction.Both);
// Get the movies directed by Sofia Coppola
Dictionary<Vertex, HashSet<Edge>> directedBySofia = pSofia.Traverse(directsType, Direction.Out);
// Get the cast of the movies directed by Sofia Coppola
//.........这里部分代码省略.........