Пример #1
0
 /// <summary>
 /// Formats a Graph Header by creating an <strong>&lt;rdf:RDF&gt;</strong> element and adding namespace definitions
 /// </summary>
 /// <param name="namespaces">Namespaces</param>
 /// <returns></returns>
 public string FormatGraphHeader(INamespaceMapper namespaces)
 {
     this._mapper = new QNameOutputMapper(namespaces);
     StringBuilder output = new StringBuilder();
     output.Append(this.GetGraphHeaderBase());
     foreach (String prefix in namespaces.Prefixes)
     {
         if (!prefix.Equals("rdf"))
         {
             if (prefix.Equals(String.Empty))
             {
                 output.Append(" xmlns=\"" + WriterHelper.EncodeForXml(namespaces.GetNamespaceUri(prefix).ToString()) + "\"");
             }
             else
             {
                 output.Append(" xmlns:" + prefix + "=\"" + WriterHelper.EncodeForXml(namespaces.GetNamespaceUri(prefix).ToString()) + "\"");
             }
         }
     }
     output.Append(">");
     return output.ToString();
 }
Пример #2
0
        /// <summary>
        /// Formats a Graph Header by creating an <strong>&lt;rdf:RDF&gt;</strong> element and adding namespace definitions
        /// </summary>
        /// <param name="namespaces">Namespaces</param>
        /// <returns></returns>
        public string FormatGraphHeader(INamespaceMapper namespaces)
        {
            this._mapper = new QNameOutputMapper(namespaces);
            StringBuilder output = new StringBuilder();

            output.Append(this.GetGraphHeaderBase());
            foreach (String prefix in namespaces.Prefixes)
            {
                if (!prefix.Equals("rdf"))
                {
                    if (prefix.Equals(String.Empty))
                    {
                        output.Append(" xmlns=\"" + WriterHelper.EncodeForXml(namespaces.GetNamespaceUri(prefix).AbsoluteUri) + "\"");
                    }
                    else
                    {
                        output.Append(" xmlns:" + prefix + "=\"" + WriterHelper.EncodeForXml(namespaces.GetNamespaceUri(prefix).AbsoluteUri) + "\"");
                    }
                }
            }
            output.Append(">");
            return(output.ToString());
        }
Пример #3
0
 /// <summary>
 /// Imports another Namespace Map into this one
 /// </summary>
 /// <param name="nsmap">Namespace Map</param>
 public void Import(INamespaceMapper nsmap)
 {
     String tempPrefix = "ns0";
     int tempPrefixID = 0;
     foreach (String prefix in nsmap.Prefixes)
     {
         if (!this._uris.ContainsKey(prefix))
         {
             //Non-colliding Namespaces get copied across
             this.AddNamespace(prefix, nsmap.GetNamespaceUri(prefix));
         }
         else
         {
             //Colliding Namespaces get remapped to new prefixes
             //Assuming the prefixes aren't already used for the same Uri
             if (!this.GetNamespaceUri(prefix).ToString().Equals(nsmap.GetNamespaceUri(prefix).ToString(), StringComparison.Ordinal))
             {
                 while (this._uris.ContainsKey(tempPrefix))
                 {
                     tempPrefixID++;
                     tempPrefix = "ns" + tempPrefixID;
                 }
                 this.AddNamespace(tempPrefix, nsmap.GetNamespaceUri(prefix));
             }
         }
     }
 }
Пример #4
0
 /// <summary>
 /// Checks whether an attribute is an rdf:type attribute.
 /// </summary>
 /// <param name="attr">The attribute to check.</param>
 /// <param name="nsMapper">The namespace prefix mappings to use to expand QNames.</param>
 /// <returns>True if the attribute is and rdf:type attribute, false otherwise.</returns>
 public static bool IsTypeAttribute(AttributeEvent attr, INamespaceMapper nsMapper)
 {
     return(nsMapper.HasNamespace(attr.Namespace) &&
            IsRdfNamespace(nsMapper.GetNamespaceUri(attr.Namespace)) &&
            attr.LocalName.Equals("type"));
 }
Пример #5
0
 /// <summary>
 /// Checks whether a give element is an rdf:li element.
 /// </summary>
 /// <param name="e">The element to test.</param>
 /// <param name="nsMapper">The namespace mappings to use when expanding element QName prefixes.</param>
 /// <returns>True if the element is an rdf:li element, false otherwise.</returns>
 public static bool IsLiElement(ElementEvent e, INamespaceMapper nsMapper)
 {
     return(nsMapper.HasNamespace(e.Namespace) &&
            IsRdfNamespace(nsMapper.GetNamespaceUri(e.Namespace)) &&
            e.LocalName.Equals("li"));
 }
Пример #6
0
        /// <summary>
        /// Resolves a QName into a Uri using the Namespace Mapper and Base Uri provided
        /// </summary>
        /// <param name="qname">QName to resolve</param>
        /// <param name="nsmap">Namespace Map to resolve against</param>
        /// <param name="baseUri">Base Uri to resolve against</param>
        /// <returns></returns>
        public static String ResolveQName(String qname, INamespaceMapper nsmap, Uri baseUri)
        {
            String output;

            if (qname.StartsWith(":"))
            {
                //QName in Default Namespace
                if (nsmap.HasNamespace(String.Empty))
                {
                    //Default Namespace Defined
                    output = nsmap.GetNamespaceUri(String.Empty).ToString() + qname.Substring(1);
                }
                else
                {
                    //No Default Namespace so use Base Uri
                    //These type of QNames are scoped to the local Uri regardless of the type of the Base Uri
                    //i.e. these always result in Hash URIs
                    if (baseUri != null)
                    {
                        output = baseUri.ToString();
                        if (output.EndsWith("#"))
                        {
                            output += qname.Substring(1);
                        }
                        else
                        {
                            output += "#" + qname.Substring(1);
                        }
                    }
                    else
                    {
                        throw new RdfParseException("Cannot resolve a QName in the Default Namespace when there is no in-scope Base URI and no Default Namespace defined");
                    }
                }
            }
            else
            {
                //QName in some other Namespace
                String[] parts = qname.Split(':');
                if (parts.Length == 1)
                {
                    output = nsmap.GetNamespaceUri(String.Empty).ToString() + parts[0];
                }
                else
                {
                    output = nsmap.GetNamespaceUri(parts[0]).ToString() + parts[1];
                }
            }

            return output;
        }
        /// <summary>
        /// Initializes a new instance.
        /// </summary>
        /// <param name="dest">The destination stream.</param>
        /// <param name="nsMapper">The namespace prefix list to use.</param>
        /// <exception cref="ArgumentNullException">Any of the arguments is <see langword="null"/>.</exception>
        /// <remarks>
        /// <para>Initializes a new instance with the given destination stream and the given namespace prefix list.
        ///   All prefixes listed in <paramref name="nsMapper"/> will be declared in the resulting Turtle output, as the writer cannot know in advance which prefixes will actually be used.</para>
        /// </remarks>
        public SequentialTurtleWriter(StreamWriter dest, INamespaceMapper nsMapper)
        {
            if (dest == null) {
                throw new ArgumentNullException("dest");
            }
            if (nsMapper == null) {
                throw new ArgumentNullException("nsMapper");
            }

            this.dest = dest;
            this.nsMapper = nsMapper;

            foreach (var prefix in nsMapper.Prefixes) {
                dest.WriteLine("@prefix {0}: <{1}> .", prefix, nsMapper.GetNamespaceUri(prefix));
            }
        }
Пример #8
0
        public static void LoadGraphPrefixes(INamespaceMapper nm)
        {
            if (nm.HasNamespace(RoboKindPrefix))
            {
                return;
            }
            string s =
                @"
@prefix : <#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix daml: <http://www.daml.org/2001/03/daml+oil#> .
@prefix log: <http://www.w3.org/2000/10/swap/log.n3#> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix virtrdf: <http://www.openlinksw.com/schemas/virtrdf#> .
@prefix sswap: <http://sswapmeet.sswap.info/sswap/#> .
@prefix sioc: <http://rdfs.org/sioc/ns#> .
@prefix sioct: <http://rdfs.org/sioc/types#> .
@prefix atom: <http://atomowl.org/ontologies/atomrdf#> .
@prefix dc: <http://purl.org/dc/elements/1.1/> .
@prefix dct: <http://purl.org/dc/terms/> .
@prefix skos: <http://www.w3.org/2004/02/skos/core#> .
@prefix geo: <http://www.w3.org/2003/01/geo/wgs84_pos#> .
@prefix wikiont: <http://sw.deri.org/2005/04/wikipedia/wikiont.owl#> .
@prefix aowl: <http://atomowl.org/ontologies/atomrdf#> .
@prefix v: <http://www.openlinksw.com/schemas/drupal_v#> .
@prefix sd: <http://www.w3.org/ns/sparql-service-description#> .
@prefix dbpprop: <http://dbpedia.org/property/> .
@prefix dbpedia-owl:	<http://dbpedia.org/ontology/> .
@prefix dc: <http://purl.org/dc/elements/1.1/> .
@prefix grddl: <http://www.w3.org/2003/g/data-view#> .
@prefix xml: <http://www.w3.org/XML/1998/namespace> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix dnr: <http://www.dotnetrdf.org/configuration#> .
@prefix dotnetrdf: <http://www.dotnetrdf.org/configuration#> .
@prefix dc: <http://purl.org/dc/elements/1.1/>.
@prefix dcterms: <http://www.purl.org/dc/terms/>.
@prefix vann: <http://purl.org/vocab/vann/>.
@prefix vs: <http://www.w3.org/2003/06/sw-vocab-status/ns#>.
@prefix fmt: <http://www.w3.org/ns/formats/>.
@prefix siprolog: <http://" + CogbotServerWithPort + @"/siprolog#> .
@prefix robokind: <" +
                RoboKindURI + @"> .
";

            string ss =
                @"
fn http://www.w3.org/2005/xpath-functions
gmlxbt http://www.opengis.net/gml/3.3/xbt
sch http://www.ascc.net/xml/schematron
# gml http://www.opengis.net/gml/3.2
gml http://www.opengis.net/gml/_
gmd http://www.isotc211.org/2005/gmd
xlink http://www.w3.org/1999/xlink
xsl  http://www.w3.org/1999/XSL/Transform 
rdf  http://www.w3.org/1999/02/22-rdf-syntax-ns# 
p3q  http://www.w3.org/2004/01/rdxh/p3q-ns-example 
p3qr http://www.example.org/P3Q-rdf# 
p3dr http://www.example.org/TR/P3P/base# 
ont  http://www.daml.org/2001/03/daml+oil# 
s http://schema.org/
xsd http://www.w3.org/2001/XMLSchema#
eco http://www.ebusiness-unibw.org/ontologies/eclass/5.1.4/
gr http://purl.org/goodrelations/v1#
dc http://purl.org/dc/elements/1.1/
ao	http://purl.org/ao/core/
aoa	http://purl.org/ao/annotea/
aof	http://purl.org/ao/foaf/
aold	http://biotea.ws/ontologies/aold/
aos	http://purl.org/ao/selectors/
aot	http://purl.org/ao/types/
bibo	http://purl.org/ontology/bibo/
bif	bif:
bio2rdf_mesh	http://bio2rdf.org/ns/mesh#
bio2rdf_ns	http://bio2rdf.org/ns/bio2rdf#
chebi	http://purl.obolibrary.org/obo/CHEBI_
cnt	http://www.w3.org/2011/content#
dawgt	http://www.w3.org/2001/sw/DataAccess/tests/test-dawg#
dbpedia	http://dbpedia.org/resource/
dbpprop	http://dbpedia.org/property/
dc	http://purl.org/dc/elements/1.1/
dcterms	http://purl.org/dc/terms/
doco	http://purl.org/spar/doco/
fma	http://purl.org/obo/owl/FMA#FMA_
fn	http://www.w3.org/2005/xpath-functions/#
foaf	http://xmlns.com/foaf/0.1/
geo	http://www.w3.org/2003/01/geo/wgs84_pos#
go	http://purl.org/obo/owl/GO#GO_
gw_property	http://genewikiplus.org/wiki/Special:URIResolver/Property-3A
gw_wiki	http://genewikiplus.org/wiki/Special:URIResolver/
icd9	http://purl.bioontology.org/ontology/ICD9-9/
math	http://www.w3.org/2000/10/swap/math#
mddb	http://purl.bioontology.org/ontology/MDDB/
meddra	http://purl.bioontology.org/ontology/MDR/
medline	http://purl.bioontology.org/ontology/MEDLINEPLUS/
mesh	http://purl.org/commons/record/mesh/
mf	http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#
mged	http://mged.sourceforge.net/ontologies/MGEDOntology.owl#
ncbitaxon	http://purl.org/obo/owl/NCBITaxon#NCBITaxon_
ncithesaurus	http://ncicb.nci.nih.gov/xml/owl/EVS/Thesaurus.owl#
nddf	http://purl.bioontology.org/ontology/NDDF/
ndfrt	http://purl.bioontology.org/ontology/NDFRT/
obi	http://purl.obolibrary.org/obo/OBI_
obo	http://www.geneontology.org/formats/oboInOwl#
omim	http://purl.bioontology.org/ontology/OMIM/
owl	http://www.w3.org/2002/07/owl#
pav	http://purl.org/swan/pav/provenance/
po	http://purl.bioontology.org/ontology/PO/
product	http://www.buy.com/rss/module/productV2/
protseq	http://purl.org/science/protein/bysequence/
prov	http://www.w3.org/ns/prov#
pw	http://purl.org/obo/owl/PW#PW_
rdf	http://www.w3.org/1999/02/22-rdf-syntax-ns#
rdfa	http://www.w3.org/ns/rdfa#
rdfdf	http://www.openlinksw.com/virtrdf-data-formats#
rdfs	http://www.w3.org/2000/01/rdf-schema#
sc	http://purl.org/science/owl/sciencecommons/
scovo	http://purl.org/NET/scovo#
sioc	http://rdfs.org/sioc/ns#
skos	http://www.w3.org/2004/02/skos/core#
snomed	http://purl.bioontology.org/ontology/SNOMEDCT/
sql	sql:
swivt	http://semantic-mediawiki.org/swivt/1.0#
symptom	http://purl.org/obo/owl/SYMP#SYMP_
taxonomy	http://www.uniprot.org/taxonomy/
umls	http://berkeleybop.org/obo/UMLS:
uniprot	http://purl.uniprot.org/core/
vcard	http://www.w3.org/2001/vcard-rdf/3.0#
vcard2006	http://www.w3.org/2006/vcard/ns#
virtcxml	http://www.openlinksw.com/schemas/virtcxml#
virtrdf	http://www.openlinksw.com/schemas/virtrdf#
void	http://rdfs.org/ns/void#
xf	http://www.w3.org/2004/07/xpath-functions
xml	http://www.w3.org/XML/1998/namespace
xsd	http://www.w3.org/2001/XMLSchema#
xsl10	http://www.w3.org/XSL/Transform/1.0
xsl1999	http://www.w3.org/1999/XSL/Transform
xslwd	http://www.w3.org/TR/WD-xsl
xsp	http://www.owl-ontologies.com/2005/08/07/xsp.owl#
yago	http://dbpedia.org/class/yago/
";

            ss = s + ss;
            foreach (string s00 in ss.Split('\n', '\r'))
            {
                if (String.IsNullOrEmpty(s00))
                {
                    continue;
                }
                var s0 = s00.Replace('\t', ' ').Trim();
                if (s0.StartsWith("#"))
                {
                    continue;
                }
                if (s0.StartsWith("@prefix "))
                {
                    s0 = s0.Substring("@prefix ".Length).TrimStart();
                    s0 = s0.TrimEnd('.', ' ');
                }
                while (s0.Contains("  "))
                {
                    s0 = s0.Replace("  ", " ");
                }
                if (String.IsNullOrEmpty(s0))
                {
                    continue;
                }
                int    spc    = s0.IndexOf(' ');
                string prefix = s0.Substring(0, spc).Trim().TrimEnd(' ', ':');
                string uri    = s0.Substring(spc).Trim();
                if (uri.StartsWith("<") && uri.EndsWith(">"))
                {
                    uri = uri.Substring(1, uri.Length - 2).Trim();
                }
                if (uri == "#")
                {
                    continue;
                    //  uri = graph.BaseUri.AbsoluteUri;
                }
                if (String.IsNullOrEmpty(prefix))
                {
                    continue;
                    prefix = ":";//"Warn("adding null prefix " + uri);
                }
                if (nm.HasNamespace(prefix))
                {
                    var prev = nm.GetNamespaceUri(prefix).ToString();
                    if (prev != uri)
                    {
                        if (uri.Length < prev.Length)
                        {
                            continue;
                        }
                    }
                }
                nm.AddNamespace(prefix, new Uri(uri));
            }
        }