예제 #1
0
        // Use the debugguer to inspect object
        public static void Main_2(string[] args)
        {
            GraphObjectTypeInfo demoVertexType =
                new GraphObjectTypeInfo(
                    id: "0ceb13cc-b23f-4918-9049-09a81807f0cd",
                    name: "Vertex Example Type",
                    type: GraphObjectType.Vertex,
                    direct_content: true,
                    oriented_edge: false);

            demoVertexType.Description = "This type is the first type of the tutorial.";

            IVertex demoVertex = new Vertex <SerializableString>(demoVertexType, new SerializableString("Node 1"));

            IGraph graph = new Graph();

            graph.AddVertex(demoVertex);

            // tutorial 2 start
            IVertex demoVertex2 = new Vertex <SerializableString>(demoVertexType, new SerializableString("Node 2"));
            IVertex demoVertex3 = new Vertex <SerializableString>(demoVertexType, new SerializableString("Node 3"));

            graph.AddVertex(demoVertex2);
            graph.AddVertex(demoVertex3);

            GraphObjectTypeInfo demoEdgeType =
                new GraphObjectTypeInfo("45fede5f-a6bc-4560-a44d-906d5043abdf", "Demo Edge Type", GraphObjectType.Edge);

            graph.CreateEdge(demoEdgeType, demoVertex, demoVertex2);
            graph.CreateEdge(demoEdgeType, demoVertex, demoVertex3);
        }
예제 #2
0
        public IEdge GetElementById(Guid id, string table)
        {
            if (!cache.ContainsKey(id))
            {
                string sql = String.Format(rawSqlProvider.SelectById, table, id);
                using (DbCommand command = (ConcreteCommand)Activator.CreateInstance(typeof(ConcreteCommand), new object[] { sql, connection }))
                {
                    using (DbDataReader reader = command.ExecuteReader())
                    {
                        if (reader.Read())
                        {
                            GraphObjectTypeInfo ti = types[reader["type_id"].ToString()];
                            Guid source            = Guid.Parse(reader["source"].ToString());
                            Guid target            = Guid.Parse(reader["target"].ToString());

                            IEdge edge = new HyperEdge(id, ti, provider, new List <Guid>()
                            {
                                source, target
                            });
                            cache.Add(id, edge);
                        }
                        else
                        {
                            throw new Exception("Missing edge data.");
                        }
                    }
                }
            }
            return(cache[id]);
        }
        IVertex InstanciateNode(Type nodeConcreteType, Guid nodeId, GraphObjectTypeInfo nodeType, string nodeContent, string lang)
        {
            List <object>       constructorParams = new List <object>();
            GraphObjectTypeInfo got = nodeType;
            string contentString    = nodeContent;

            Type    genericType   = nodeConcreteType;
            IVertex v             = null;
            Type    vertexContent = typeof(SerializableString);

            if (vertexContentTypeMap.ContainsKey(got.Id))
            {
                vertexContent = vertexContentTypeMap[got.Id];
            }

            IStringSerializable content = Activator.CreateInstance(vertexContent) as IStringSerializable;

            content.Deserialize(contentString);

            Type instanceType = nodeConcreteType;

            if (nodeConcreteType.IsGenericTypeDefinition)
            {
                instanceType = genericType.MakeGenericType(vertexContent);
            }
            v = Activator.CreateInstance(instanceType, new object[] { got, content, lang, nodeId }) as IVertex;

            return(v);
        }
예제 #4
0
        public void RemoveVertexSimpleGraph()
        {
            GraphObjectTypeInfo vertexType = new GraphObjectTypeInfo("33ca7d63-78e0-44b2-90b2-279f20f48856", "Test Vertex Type", GraphObjectType.Vertex);
            GraphObjectTypeInfo edgeType   = new GraphObjectTypeInfo("9eaa1218-14d9-46cd-9678-c2a29128982f", "Test Edge Type", GraphObjectType.Edge);

            Graph   g      = new Graph();
            IVertex origin = VertexExtensions.CreateTextVertex(vertexType, "v1");
            IVertex target = VertexExtensions.CreateTextVertex(vertexType, "v2");

            g.AddVertex(origin);
            g.AddVertex(target);
            g.CreateEdge(edgeType, origin, target);

            Assert.AreEqual <int>(1, origin.Links.Count);
            Assert.AreEqual <int>(1, target.Links.Count);

            g.RemoveVertex(target);

            List <IVertex> results = g.SearchNode("", "v2");

            Assert.IsNull(results);
            Assert.AreEqual <int>(0, origin.Links.Count);
            // not in the graph anymore but should have the reference to the edge deleted
            Assert.AreEqual <int>(0, target.Links.Count);
        }
        private void FillEdgeSpecificInformation(XElement node, GraphObjectTypeInfo typeInfo)
        {
            string orientationStr = node.Attribute(nameProvider.TypeIsOrientedEdgeAttribute)?.Value;

            ThrowErrorIfNull(orientationStr, "Missing edge orientation.");
            typeInfo.Oriented = orientationStr.Equals(XmlHeaderNames.StringBooleanValueTrue);
            // TODO
        }
        private void LoadTypeDeclarations(XDocument xdoc)
        {
            XElement typesNode = xdoc.Root.Element(nameProvider.TypeListElement);

            ThrowErrorIfNull(typesNode, $"Missing {nameProvider.TypeListElement} node.");

            headerInfo.Types      = typesNode.Elements().Count();
            typeNumericAliasTable = new GraphObjectTypeInfo[headerInfo.Types];

            LoadTypes(typesNode, GraphObjectType.Vertex);
            LoadTypes(typesNode, GraphObjectType.Edge);
        }
        private void LoadTypes(XElement parentNode, GraphObjectType kind)
        {
            IEnumerable <XElement> types = kind == GraphObjectType.Vertex ?
                                           parentNode.Elements(nameProvider.VertexTypeElement).Where(e => e.Attribute(nameProvider.TypeKindAttribute).Value == nameProvider.TypeKindAttributeValueVertex) :
                                           parentNode.Elements(nameProvider.EdgeTypeElement).Where(e => e.Attribute(nameProvider.TypeKindAttribute).Value == nameProvider.TypeKindAttributeValueEdge);

            if (types != null)
            {
                foreach (XElement typeElement in types)
                {
                    string id = typeElement.Attribute(nameProvider.TypeExternalIdAttribute)?.Value;
                    ThrowErrorIfNull(id, "Missing type external id.");

                    string internalId = typeElement.Attribute(nameProvider.TypeInternalIdAttribute)?.Value;
                    ThrowErrorIfNull(id, "Missing type internal id.");
                    int internalTypeId = 0;
                    if (!Int32.TryParse(internalId, out internalTypeId))
                    {
                        ThrowParseException("Internal id not convertible to integer.");
                    }

                    string name = typeElement.Element(nameProvider.TypeNameElement)?.Value;
                    ThrowErrorIfNull(id, "Missing type name.");

                    string description = typeElement.Element(nameProvider.TypeDescriptionElement)?.Value;
                    ThrowErrorIfNull(id, "Missing type description.");

                    string orientedString = typeElement.Attribute(nameProvider.TypeIsOrientedEdgeAttribute)?.Value;
                    bool   oriented       = false;
                    if (orientedString != null)
                    {
                        oriented = Boolean.Parse(orientedString);
                    }

                    string directContentString = typeElement.Attribute(nameProvider.TypeIsDirectContentAttribute)?.Value;
                    bool   directContent       = false;
                    if (directContentString != null)
                    {
                        directContent = Boolean.Parse(directContentString);
                    }

                    Guid guid = Guid.Parse(id);                                                                        // TODO checker les erreurs

                    GraphObjectTypeInfo typeInfo = new GraphObjectTypeInfo(guid, name, kind, oriented, directContent); // TODO fixer correctement direct_content
                    typeInfo.Description = description;

                    typeNumericAliasTable[internalTypeId] = typeInfo;
                }
            }
        }
예제 #8
0
        private object InstanciateEdge(GraphObjectTypeInfo type, Type defaultConcreteType, IEnumerable <object> additionalParams)
        {
            List <object> constructorParams = new List <object>();
            Type          concreteType      = defaultConcreteType;

            constructorParams.Add(type);

            if (typeAssociation.ContainsKey(type.Id))
            {
                concreteType = typeAssociation[type.Id];
            }
            constructorParams.AddRange(additionalParams);

            return(Activator.CreateInstance(concreteType, constructorParams.ToArray()));
        }
        private Graph GetTestGraph()
        {
            GraphObjectTypeInfo vertexType = new GraphObjectTypeInfo("33ca7d63-78e0-44b2-90b2-279f20f48856", "Test Vertex Type", GraphObjectType.Vertex);
            GraphObjectTypeInfo edgeType   = new GraphObjectTypeInfo("9eaa1218-14d9-46cd-9678-c2a29128982f", "Test Edge Type", GraphObjectType.Edge);

            Graph   g      = new Graph();
            IVertex origin = VertexExtensions.CreateTextVertex(vertexType, "v1");
            IVertex target = VertexExtensions.CreateTextVertex(vertexType, "v2");

            g.AddVertex(origin);
            g.AddVertex(target);
            g.CreateEdge(edgeType, origin, target);

            return(g);
        }
예제 #10
0
        public void RelationshipToSelf()
        {
            GraphObjectTypeInfo        vertexType = new GraphObjectTypeInfo("33ca7d63-78e0-44b2-90b2-279f20f48856", "Test Vertex Type", GraphObjectType.Vertex);
            OrientedBinaryEdgeTypeInfo edgeType   = new OrientedBinaryEdgeTypeInfo("9eaa1218-14d9-46cd-9678-c2a29128982f", "Test Binary Oriented Edge Type");

            Graph   g     = new Graph();
            IVertex first = VertexExtensions.CreateTextVertex(vertexType, "v1");

            g.AddVertex(first);

            g.CreateEdge(edgeType, first, first);

            IEnumerable <IVertex> list = first.Successors(edgeType);

            Assert.AreEqual(1, list.Count());
        }
예제 #11
0
        // Use the debugguer to inspect object
        public static void Main(string[] args)
        {
            GraphObjectTypeInfo demoVertexType =
                new GraphObjectTypeInfo(
                    id: "0ceb13cc-b23f-4918-9049-09a81807f0cd",
                    name: "Vertex Example Type",
                    type: GraphObjectType.Vertex,
                    direct_content: true,
                    oriented_edge: false);

            demoVertexType.Description = "This type is the first type of the tutorial.";

            IVertex demoVertex = new Vertex <SerializableString>(demoVertexType, new SerializableString("Node 1"));

            IGraph graph = new Graph();

            graph.AddVertex(demoVertex);
        }
        public SqlGraphObjectStore(DbConnection connection, string tableName)
        {
            this.connection = connection;
            table           = tableName;

            using (DbCommand req = (ConcreteDbCommand)Activator.CreateInstance(typeof(ConcreteDbCommand), new object[] { $"SELECT * FROM Type", connection }))
            {
                using (DbDataReader reader = req.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        string id = reader["id"].ToString();
                        var    t  = new GraphObjectTypeInfo(Guid.Parse(id),
                                                            reader["name"].ToString(), (bool)reader["is_vertex"] ? GraphObjectType.Vertex : GraphObjectType.Edge);
                        types.Add(id, t);
                    }
                    reader.Close();
                }
            }
        }
예제 #13
0
        public void RemoveEdgeSimpleGraph()
        {
            GraphObjectTypeInfo vertexType = new GraphObjectTypeInfo("33ca7d63-78e0-44b2-90b2-279f20f48856", "Test Vertex Type", GraphObjectType.Vertex);
            GraphObjectTypeInfo edgeType   = new GraphObjectTypeInfo("9eaa1218-14d9-46cd-9678-c2a29128982f", "Test Edge Type", GraphObjectType.Edge);

            Graph   g      = new Graph();
            IVertex origin = VertexExtensions.CreateTextVertex(vertexType, "v1");
            IVertex target = VertexExtensions.CreateTextVertex(vertexType, "v2");

            g.AddVertex(origin);
            g.AddVertex(target);
            IEdge edge = g.CreateEdge(edgeType, origin, target);

            Assert.AreEqual <int>(1, origin.Links.Count);
            Assert.AreEqual <int>(1, target.Links.Count);
            Assert.AreEqual <int>(1, g.EdgesNumber);

            g.RemoveEdge(edge);

            Assert.AreEqual <int>(0, origin.Links.Count);
            Assert.AreEqual <int>(0, target.Links.Count);
            Assert.AreEqual <int>(0, g.EdgesNumber);
        }
예제 #14
0
 /// <summary>
 /// Permet d'associer le type qui représente le contenu d'un noeud si celui celui-ci
 /// doit être différent de SerializableString.
 /// </summary>
 /// <typeparam name="Class"></typeparam>
 /// <param name="type"></param>
 public void AssociateVertexContentTypeToDeserializer <Class>(GraphObjectTypeInfo type)
     where Class : IStringSerializable, new()
 {
     vertexContentTypeMap.Add(type.Id, typeof(Class));
 }
예제 #15
0
        public Graph ReadGraph(StreamReader sr)
        {
            Graph graph = new Graph();

            GraphObjectTypeInfo[] aliasTable = new GraphObjectTypeInfo[0];
            IVertex[]             nodesTable = new IVertex[0];
            lineNumber = 0;

            while (!sr.EndOfStream)
            {
                lineNumber++;
                string   line  = sr.ReadLine();
                string[] parts = line.Split('|');
                switch (parts[0])
                {
                case "H":
                    HeaderInfo hInfo = ParseHeader(parts[1]);
                    aliasTable = new GraphObjectTypeInfo[hInfo.DeclaredTypes];
                    nodesTable = new IVertex[hInfo.Vertices];
                    break;

                case "A":
                    TypeInfo typeInfo = ParseTypeDeclaration(line);
                    aliasTable[typeInfo.LocalId] = new GraphObjectTypeInfo(typeInfo.ExternalId, typeInfo.Name, typeInfo.ObjectType);
                    break;

                case "N":
                    List <object>       constructorParams = new List <object>();
                    GraphObjectTypeInfo got = aliasTable[Int32.Parse(parts[2])];
                    string contentString    = parts[3];

                    // si un type deserialisable concret est enregistré
                    // on crée une instance 'i' de IStringSerializable à partir du type enregistré
                    // on désérialise la chaîne depuis 'i'
                    // on crée une instance de StringSerializableVertex dont on fixe le contenu à 'i'
                    // sinon
                    // on crée une instance de Vertex<string> et on y la chaîne 'content'

                    Type    genericType   = typeof(Vertex <>);
                    IVertex v             = null;
                    Type    vertexContent = typeof(SerializableString);
                    if (vertexContentTypeMap.ContainsKey(got.Id))
                    {
                        vertexContent = vertexContentTypeMap[got.Id];
                    }

                    IStringSerializable content = Activator.CreateInstance(vertexContent) as IStringSerializable;
                    content.Deserialize(contentString);
                    Type specializedGenericType = genericType.MakeGenericType(vertexContent);
                    v = Activator.CreateInstance(specializedGenericType, new object[] { got, content }) as IVertex;

                    nodesTable[Int32.Parse(parts[1])] = v;
                    break;

                case "E":
                    List <IVertex>      vertices = new List <IVertex>();
                    GraphObjectTypeInfo type     = aliasTable[Int32.Parse(parts[1])];
                    foreach (string v_str in parts[2].Split(','))
                    {
                        vertices.Add(nodesTable[long.Parse(v_str)]);
                    }
                    InstanciateEdge(type, typeof(HyperEdge), vertices);
                    break;
                }
            }

            foreach (IVertex node in nodesTable)
            {
                graph.AddVertex(node as IVertex);
            }
            return(graph);
        }
예제 #16
0
 public EditableVertex(GraphObjectTypeInfo type, SerializableString content, string lang, Guid id)
     : base(type, content, lang, id)
 {
 }
예제 #17
0
 public void SetType(GraphObjectTypeInfo type)
 {
     base.type = type;
 }
 private void FillVertexSpecificInformation(XElement node, GraphObjectTypeInfo typeInfo)
 {
     // TODO
 }
예제 #19
0
        // Use the debugguer to inspect object
        public static void Main_3(string[] args)
        {
            GraphObjectTypeInfo demoVertexType =
                new GraphObjectTypeInfo(
                    id: "0ceb13cc-b23f-4918-9049-09a81807f0cd",
                    name: "Vertex Example Type",
                    type: GraphObjectType.Vertex,
                    direct_content: true,
                    oriented_edge: false);

            demoVertexType.Description = "This type is the first type of the tutorial.";

            IVertex demoVertex = new Vertex <SerializableString>(demoVertexType, new SerializableString("Node 1"));

            IGraph graph = new Graph();

            graph.AddVertex(demoVertex);

            // tutorial 2 start
            IVertex demoVertex2 = new Vertex <SerializableString>(demoVertexType, new SerializableString("Node 2"));
            IVertex demoVertex3 = new Vertex <SerializableString>(demoVertexType, new SerializableString("Node 3"));

            graph.AddVertex(demoVertex2);
            graph.AddVertex(demoVertex3);

            GraphObjectTypeInfo demoEdgeType =
                new GraphObjectTypeInfo("45fede5f-a6bc-4560-a44d-906d5043abdf", "Demo Edge Type", GraphObjectType.Edge);

            graph.CreateEdge(demoEdgeType, demoVertex, demoVertex2);
            graph.CreateEdge(demoEdgeType, demoVertex, demoVertex3);

            // tutorial 3 start
            // Performing a Search
            Console.WriteLine("Default indexed string of Node 1:" + demoVertex);
            List <IVertex> results = graph.SearchNode("", "Node 1");

            Console.WriteLine("Number of results: " + results.Count);
            Console.WriteLine("Result node " + results[0]);

            // Traversing the Graph
            Console.WriteLine("Number of links from Node 1: " + demoVertex.Links.Count);

            List <IVertex> linkedNodes = new List <IVertex>();

            foreach (IEdge edge in demoVertex.Links)
            {
                foreach (IVertex v in edge.GetLinkedObjects(GraphObjectType.Vertex))
                {
                    if (v.ObjectId != demoVertex.ObjectId)
                    {
                        linkedNodes.Add(v);
                    }
                }
            }
            linkedNodes.ForEach(n => Console.WriteLine(n));

            // Get Successors (the Easy Way)
            OrientedBinaryEdgeTypeInfo relationship = new OrientedBinaryEdgeTypeInfo("45fede5f-a6bc-4560-a44d-906d5043abdf", "", "");

            linkedNodes = demoVertex.Successors(relationship);
            linkedNodes.ForEach(n => Console.WriteLine(n));
        }
예제 #20
0
 /// <summary>
 /// Permet de définir la classe concrète qui fera office d'implémentation d'un IEdge ou IVertex.
 /// </summary>
 /// <typeparam name="Class"></typeparam>
 /// <param name="type"></param>
 public void AssociateGraphTypeToConcreteClass <Class>(GraphObjectTypeInfo type)
 {
     AssociateGraphTypeToConcreteClass <Class>(type.Id);
 }