Exemplo n.º 1
0
        private static void WriteNode(XmlWriter writer, string id, string label)
        {
            writer.WriteStartElement(GraphMLSpecsHelper.Node);
            writer.WriteAttributeString(GraphMLSpecsHelper.Id, id);

            GraphMLWriter.WriteData(writer, GraphMLSpecsHelper.NodeLabel, label);

            writer.WriteEndElement();
        }
Exemplo n.º 2
0
        private static void WriteGraphML(XmlWriter writer, ITripleStore store, bool collapseLiterals)
        {
            writer.WriteStartElement(GraphMLSpecsHelper.GraphML, GraphMLSpecsHelper.NS);

            GraphMLWriter.WriteKey(writer, GraphMLSpecsHelper.EdgeLabel, GraphMLSpecsHelper.Edge);
            GraphMLWriter.WriteKey(writer, GraphMLSpecsHelper.NodeLabel, GraphMLSpecsHelper.Node);

            foreach (var graph in store.Graphs)
            {
                GraphMLWriter.WriteGraph(writer, graph, collapseLiterals);
            }

            writer.WriteEndElement();
        }
Exemplo n.º 3
0
        private static void WriteEdge(XmlWriter writer, Triple triple, bool collapseLiterals)
        {
            writer.WriteStartElement(GraphMLSpecsHelper.Edge);
            writer.WriteAttributeString(GraphMLSpecsHelper.Source, triple.Subject.GetHashCode().ToString());

            writer.WriteStartAttribute(GraphMLSpecsHelper.Target);

            var id = GraphMLWriter.CalculateNodeId(triple.Object, triple, collapseLiterals);

            writer.WriteString(id.GetHashCode().ToString());

            GraphMLWriter.WriteData(writer, GraphMLSpecsHelper.EdgeLabel, triple.Predicate.ToString());

            writer.WriteEndElement();
        }
Exemplo n.º 4
0
        private static void WriteGraph(XmlWriter writer, IGraph graph, bool collapseLiterals)
        {
            writer.WriteStartElement(GraphMLSpecsHelper.Graph);

            // Named graphs
            if (graph.BaseUri != null)
            {
                writer.WriteAttributeString(GraphMLSpecsHelper.Id, graph.BaseUri.AbsoluteUri);
            }

            // RDF is always a directed graph
            writer.WriteAttributeString(GraphMLSpecsHelper.Edgedefault, GraphMLSpecsHelper.Directed);

            GraphMLWriter.WriteTriples(writer, graph, collapseLiterals);

            writer.WriteEndElement();
        }
Exemplo n.º 5
0
        private static void WriteTriples(XmlWriter writer, IGraph graph, bool collapseLiterals)
        {
            var nodesAlreadyWritten = new HashSet <object>();

            foreach (var triple in graph.Triples)
            {
                foreach (var node in new[] { triple.Subject, triple.Object })
                {
                    var id = GraphMLWriter.CalculateNodeId(node, triple, collapseLiterals);

                    // Skip if already written
                    if (nodesAlreadyWritten.Add(id))
                    {
                        GraphMLWriter.WriteNode(writer, id.GetHashCode().ToString(), node.ToString());
                    }
                }

                GraphMLWriter.WriteEdge(writer, triple, collapseLiterals);
            }
        }
Exemplo n.º 6
0
 /// <summary>
 /// Saves a triple store to an XML writer in GraphML format.
 /// </summary>
 /// <param name="store">The source triple store.</param>
 /// <param name="output">The target XML writer.</param>
 public void Save(ITripleStore store, XmlWriter output)
 {
     GraphMLWriter.WriteGraphML(output, store, this.CollapseLiterals);
 }