Example #1
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();
        }
Example #2
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);
            }
        }