示例#1
0
 /// <summary>
 /// Converts a Sesame Value to a dotNetRDF Node
 /// </summary>
 /// <param name="value">Value</param>
 /// <param name="mapping">Blank Node Mapping</param>
 /// <returns></returns>
 internal static INode FromSesameValue(dotSesame.Value value, SesameMapping mapping)
 {
     if (value is dotSesame.URI)
     {
         return(mapping.Graph.CreateUriNode(new Uri(((dotSesame.URI)value).stringValue())));
     }
     else if (value is dotSesame.Literal)
     {
         dotSesame.Literal lit = (dotSesame.Literal)value;
         if (lit.getDatatype() != null)
         {
             return(mapping.Graph.CreateLiteralNode(lit.stringValue(), FromSesameUri(lit.getDatatype())));
         }
         else if (lit.getLanguage() != null)
         {
             return(mapping.Graph.CreateLiteralNode(lit.stringValue(), lit.getLanguage()));
         }
         else
         {
             return(mapping.Graph.CreateLiteralNode(lit.stringValue()));
         }
     }
     else if (value is dotSesame.BNode)
     {
         dotSesame.BNode bnode = (dotSesame.BNode)value;
         if (mapping.InputMapping.ContainsKey(bnode))
         {
             return(mapping.InputMapping[bnode]);
         }
         else
         {
             INode n = mapping.Graph.CreateBlankNode();
             lock (mapping)
             {
                 if (!mapping.InputMapping.ContainsKey(bnode))
                 {
                     mapping.InputMapping.Add(bnode, n);
                 }
                 else
                 {
                     n = mapping.InputMapping[bnode];
                 }
                 if (!mapping.OutputMapping.ContainsKey(n))
                 {
                     mapping.OutputMapping.Add(n, bnode);
                 }
             }
             return(n);
         }
     }
     else
     {
         throw new RdfException("Unable to convert unexpected Sesame Value Type to a dotNetRDF INode");
     }
 }
示例#2
0
        /// <summary>
        /// Converts a dotNetRDF Node to a Sesame Value
        /// </summary>
        /// <param name="n">Node</param>
        /// <param name="mapping">Blank Node Mapping</param>
        /// <returns></returns>
        internal static dotSesame.Value ToSesameValue(INode n, SesameMapping mapping)
        {
            switch (n.NodeType)
            {
            case NodeType.Uri:
                return(mapping.ValueFactory.createURI(((IUriNode)n).Uri.ToString()));

            case NodeType.Literal:
                ILiteralNode lit = (ILiteralNode)n;
                if (lit.DataType != null)
                {
                    return(mapping.ValueFactory.createLiteral(lit.Value, ToSesameUri(lit.DataType, mapping)));
                }
                else if (!lit.Language.Equals(String.Empty))
                {
                    return(mapping.ValueFactory.createLiteral(lit.Value, lit.Language));
                }
                else
                {
                    return(mapping.ValueFactory.createLiteral(lit.Value));
                }

            case NodeType.Blank:
                if (mapping.OutputMapping.ContainsKey(n))
                {
                    return(mapping.OutputMapping[n]);
                }
                else
                {
                    dotSesame.BNode bnode = mapping.ValueFactory.createBNode();

                    lock (mapping)
                    {
                        if (!mapping.OutputMapping.ContainsKey(n))
                        {
                            mapping.OutputMapping.Add(n, bnode);
                        }
                        else
                        {
                            bnode = mapping.OutputMapping[n];
                        }
                        if (!mapping.InputMapping.ContainsKey(bnode))
                        {
                            mapping.InputMapping.Add(bnode, n);
                        }
                    }
                    return(bnode);
                }

            default:
                throw new RdfException("Only URI, Blank Node and Literal Objects are supported by Sesame");
            }
        }
示例#3
0
 public dotSesame.BNode createBNode(string str)
 {
     dotSesame.BNode bnode = this._mapping.ValueFactory.createBNode(str);
     if (!this._mapping.InputMapping.ContainsKey(bnode))
     {
         this._mapping.InputMapping.Add(bnode, this._mapping.Graph.CreateBlankNode());
     }
     if (!this._mapping.OutputMapping.ContainsKey(this._mapping.InputMapping[bnode]))
     {
         this._mapping.OutputMapping.Add(this._mapping.InputMapping[bnode], bnode);
     }
     return(bnode);
 }
示例#4
0
        public override IBlankNode CreateBlankNode()
        {
            IBlankNode n = base.CreateBlankNode();

            dotSesame.BNode bnode = this._mapping.ValueFactory.createBNode();

            lock (this._mapping)
            {
                if (!this._mapping.OutputMapping.ContainsKey(n))
                {
                    this._mapping.OutputMapping.Add(n, bnode);
                }
                if (!this._mapping.InputMapping.ContainsKey(bnode))
                {
                    this._mapping.InputMapping.Add(bnode, n);
                }
            }

            return(n);
        }
示例#5
0
 /// <summary>
 /// Converts a Sesame Resource to a dotNetRDF Node
 /// </summary>
 /// <param name="resource">Resource</param>
 /// <param name="mapping">Blank Node Mapping</param>
 /// <returns></returns>
 internal static INode FromSesameResource(dotSesame.Resource resource, SesameMapping mapping)
 {
     if (resource is dotSesame.URI)
     {
         return(mapping.Graph.CreateUriNode(new Uri(((dotSesame.URI)resource).stringValue())));
     }
     else if (resource is dotSesame.BNode)
     {
         dotSesame.BNode bnode = (dotSesame.BNode)resource;
         if (mapping.InputMapping.ContainsKey(bnode))
         {
             return(mapping.InputMapping[bnode]);
         }
         else
         {
             INode n = mapping.Graph.CreateBlankNode();
             lock (mapping)
             {
                 if (!mapping.InputMapping.ContainsKey(bnode))
                 {
                     mapping.InputMapping.Add(bnode, n);
                 }
                 else
                 {
                     n = mapping.InputMapping[bnode];
                 }
                 if (!mapping.OutputMapping.ContainsKey(n))
                 {
                     mapping.OutputMapping.Add(n, bnode);
                 }
             }
             return(n);
         }
     }
     else
     {
         throw new RdfException("Unable to convert unexpected Sesame Resource Type to a dotNetRDF INode");
     }
 }
示例#6
0
        /// <summary>
        /// Converts a dotNetRDF Node to a Sesame Resource
        /// </summary>
        /// <param name="n">Node</param>
        /// <param name="mapping">Blank Node Mapping</param>
        /// <returns></returns>
        internal static dotSesame.Resource ToSesameResource(INode n, SesameMapping mapping)
        {
            switch (n.NodeType)
            {
            case NodeType.Uri:
                return(mapping.ValueFactory.createURI(((IUriNode)n).Uri.ToString()));

            case NodeType.Blank:
                if (mapping.OutputMapping.ContainsKey(n))
                {
                    return(mapping.OutputMapping[n]);
                }
                else
                {
                    dotSesame.BNode bnode = mapping.ValueFactory.createBNode();

                    lock (mapping)
                    {
                        if (!mapping.OutputMapping.ContainsKey(n))
                        {
                            mapping.OutputMapping.Add(n, bnode);
                        }
                        else
                        {
                            bnode = mapping.OutputMapping[n];
                        }
                        if (!mapping.InputMapping.ContainsKey(bnode))
                        {
                            mapping.InputMapping.Add(bnode, n);
                        }
                    }
                    return(bnode);
                }

            default:
                throw new RdfException("Only URI and Blank Node subjects are supported in Sesame");
            }
        }
示例#7
0
        public override IBlankNode CreateBlankNode(string nodeId)
        {
            IBlankNode n = this.GetBlankNode(nodeId);

            if (n == null)
            {
                n = this.CreateBlankNode(nodeId);
            }
            dotSesame.BNode bnode = this._mapping.ValueFactory.createBNode(nodeId);

            lock (this._mapping)
            {
                if (!this._mapping.OutputMapping.ContainsKey(n))
                {
                    this._mapping.OutputMapping.Add(n, bnode);
                }
                if (!this._mapping.InputMapping.ContainsKey(bnode))
                {
                    this._mapping.InputMapping.Add(bnode, n);
                }
            }

            return(n);
        }