コード例 #1
0
        public void ReadGraph(IRdfGraph graph)
        {
            IRdfEdgeCollection edges = graph.Edges;

            for (int index = 0; index < edges.Count; ++index)
            {
                IRdfEdge edge = edges[index];

                OnNewStatement(ParseEdge(edge));
            }
        }
コード例 #2
0
        public Statement ParseEdge(IRdfEdge edge)
        {
            // Nasty hack follows
            UriRef thePredicate = itsResourceFactory.MakeUriRef(edge.ID);

            NodeType subjectNodeType;
            NodeType objectNodeType;

            if (edge.ParentNode.ID.StartsWith("blankID:"))
            {
                subjectNodeType = NodeType.BLANK_NODE;
            }
            else
            {
                subjectNodeType = NodeType.URIREF;
            }

            if (edge.ChildNode is IRdfLiteral)
            {
                if (((IRdfLiteral)edge.ChildNode).Datatype == "")
                {
                    objectNodeType = NodeType.PLAIN_LITERAL;
                }
                else
                {
                    objectNodeType = NodeType.TYPED_LITERAL;
                }
            }
            else if (edge.ChildNode.ID.StartsWith("blankID:"))
            {
                objectNodeType = NodeType.BLANK_NODE;
            }
            else
            {
                objectNodeType = NodeType.URIREF;
            }


            if (subjectNodeType == NodeType.BLANK_NODE)
            {
                BlankNode theSubject = itsResourceFactory.MakeBlankNode("drive" + edge.ParentNode.ID.Substring(8));

                if (objectNodeType == NodeType.BLANK_NODE)
                {
                    BlankNode theObject = itsResourceFactory.MakeBlankNode("drive" + edge.ChildNode.ID.Substring(8));
                    return(itsStatementFactory.MakeStatement(theSubject, thePredicate, theObject));
                }
                else if (objectNodeType == NodeType.URIREF)
                {
                    UriRef theObject = itsResourceFactory.MakeUriRef(edge.ChildNode.ID);
                    return(itsStatementFactory.MakeStatement(theSubject, thePredicate, theObject));
                }
                else if (objectNodeType == NodeType.PLAIN_LITERAL)
                {
                    PlainLiteral theObject;
                    if (((IRdfLiteral)edge.ChildNode).LangID == null)
                    {
                        theObject = itsResourceFactory.MakePlainLiteral(((IRdfLiteral)edge.ChildNode).Value);
                    }
                    else
                    {
                        theObject = itsResourceFactory.MakePlainLiteral(((IRdfLiteral)edge.ChildNode).Value, ((IRdfLiteral)edge.ChildNode).LangID);
                    }
                    return(itsStatementFactory.MakeStatement(theSubject, thePredicate, theObject));
                }
                else if (objectNodeType == NodeType.TYPED_LITERAL)
                {
                    TypedLiteral theObject = itsResourceFactory.MakeTypedLiteral(((IRdfLiteral)edge.ChildNode).Value, ((IRdfLiteral)edge.ChildNode).Datatype);
                    return(itsStatementFactory.MakeStatement(theSubject, thePredicate, theObject));
                }
            }
            else
            {
                UriRef theSubject = itsResourceFactory.MakeUriRef(edge.ParentNode.ID);

                if (objectNodeType == NodeType.BLANK_NODE)
                {
                    BlankNode theObject = itsResourceFactory.MakeBlankNode("drive" + edge.ChildNode.ID.Substring(8));
                    return(itsStatementFactory.MakeStatement(theSubject, thePredicate, theObject));
                }
                else if (objectNodeType == NodeType.URIREF)
                {
                    UriRef theObject = itsResourceFactory.MakeUriRef(edge.ChildNode.ID);
                    return(itsStatementFactory.MakeStatement(theSubject, thePredicate, theObject));
                }
                else if (objectNodeType == NodeType.PLAIN_LITERAL)
                {
                    PlainLiteral theObject;
                    if (((IRdfLiteral)edge.ChildNode).LangID == null)
                    {
                        theObject = itsResourceFactory.MakePlainLiteral(((IRdfLiteral)edge.ChildNode).Value);
                    }
                    else
                    {
                        theObject = itsResourceFactory.MakePlainLiteral(((IRdfLiteral)edge.ChildNode).Value, ((IRdfLiteral)edge.ChildNode).LangID);
                    }
                    return(itsStatementFactory.MakeStatement(theSubject, thePredicate, theObject));
                }
                else if (objectNodeType == NodeType.TYPED_LITERAL)
                {
                    TypedLiteral theObject = itsResourceFactory.MakeTypedLiteral(((IRdfLiteral)edge.ChildNode).Value, ((IRdfLiteral)edge.ChildNode).Datatype);
                    return(itsStatementFactory.MakeStatement(theSubject, thePredicate, theObject));
                }
            }

            return(null);
        }