Пример #1
0
 public virtual int CompareTo(RDFDataset.Node o)
 {
     if (this.IsIRI())
     {
         if (!o.IsIRI())
         {
             // IRIs > everything
             return(1);
         }
     }
     else
     {
         if (this.IsBlankNode())
         {
             if (o.IsIRI())
             {
                 // IRI > blank node
                 return(-1);
             }
             else
             {
                 if (o.IsLiteral())
                 {
                     // blank node > literal
                     return(1);
                 }
             }
         }
     }
     return(string.CompareOrdinal(this.GetValue(), o.GetValue()));
 }
Пример #2
0
 public override int CompareTo(RDFDataset.Node o)
 {
     if (o == null)
     {
         // valid nodes are > null nodes
         return(1);
     }
     if (o.IsIRI())
     {
         // literals < iri
         return(-1);
     }
     if (o.IsBlankNode())
     {
         // blank node < iri
         return(-1);
     }
     if (this.GetLanguage() == null && ((RDFDataset.Literal)o).GetLanguage() != null)
     {
         return(-1);
     }
     else
     {
         if (this.GetLanguage() != null && ((RDFDataset.Literal)o).GetLanguage() == null)
         {
             return(1);
         }
     }
     if (this.GetDatatype() != null)
     {
         return(string.CompareOrdinal(this.GetDatatype(), ((RDFDataset.Literal)o).GetDatatype
                                          ()));
     }
     else
     {
         if (((RDFDataset.Literal)o).GetDatatype() != null)
         {
             return(-1);
         }
     }
     return(0);
 }
Пример #3
0
        internal static string ToNQuad(RDFDataset.Quad triple, string graphName, string bnode
                                       )
        {
            RDFDataset.Node s    = triple.GetSubject();
            RDFDataset.Node p    = triple.GetPredicate();
            RDFDataset.Node o    = triple.GetObject();
            string          quad = string.Empty;

            // subject is an IRI or bnode
            if (s.IsIRI())
            {
                quad += "<" + Escape(s.GetValue()) + ">";
            }
            else
            {
                // normalization mode
                if (bnode != null)
                {
                    quad += bnode.Equals(s.GetValue()) ? "_:a" : "_:z";
                }
                else
                {
                    // normal mode
                    quad += s.GetValue();
                }
            }
            if (p.IsIRI())
            {
                quad += " <" + Escape(p.GetValue()) + "> ";
            }
            else
            {
                // otherwise it must be a bnode (TODO: can we only allow this if the
                // flag is set in options?)
                quad += " " + Escape(p.GetValue()) + " ";
            }
            // object is IRI, bnode or literal
            if (o.IsIRI())
            {
                quad += "<" + Escape(o.GetValue()) + ">";
            }
            else
            {
                if (o.IsBlankNode())
                {
                    // normalization mode
                    if (bnode != null)
                    {
                        quad += bnode.Equals(o.GetValue()) ? "_:a" : "_:z";
                    }
                    else
                    {
                        // normal mode
                        quad += o.GetValue();
                    }
                }
                else
                {
                    string escaped = Escape(o.GetValue());
                    quad += "\"" + escaped + "\"";
                    if (JSONLDConsts.RdfLangstring.Equals(o.GetDatatype()))
                    {
                        quad += "@" + o.GetLanguage();
                    }
                    else
                    {
                        if (!JSONLDConsts.XsdString.Equals(o.GetDatatype()))
                        {
                            quad += "^^<" + Escape(o.GetDatatype()) + ">";
                        }
                    }
                }
            }
            // graph
            if (graphName != null)
            {
                if (graphName.IndexOf("_:") != 0)
                {
                    quad += " <" + Escape(graphName) + ">";
                }
                else
                {
                    if (bnode != null)
                    {
                        quad += " _:g";
                    }
                    else
                    {
                        quad += " " + graphName;
                    }
                }
            }
            quad += " .\n";
            return(quad);
        }