Ejemplo n.º 1
0
 /// <summary>Creates a new instance of <see cref="TripleStoreAdapter" />.</summary>
 /// <param name="store">The underlying triple store</param>
 /// <param name="sparqlCommandFactory">SPARQL command factory.</param>
 /// <param name="sparqlCommandExecutionStrategyFactory">SPRAQL command execution strategy factory.</param>
 public TripleStoreAdapter(ITripleStore store, ISparqlCommandFactory sparqlCommandFactory, ISparqlCommandExecutionStrategyFactory sparqlCommandExecutionStrategyFactory)
 {
     _store = store;
     _sparqlCommandFactory = sparqlCommandFactory;
     _sparqlCommandExecutionStrategyFactory = sparqlCommandExecutionStrategyFactory;
     _namespaces = new NamespaceMapper(true);
     _namespaces.AddNamespace("foaf", new Uri("http://xmlns.com/foaf/0.1/"));
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Handles Namespace Declarations passing them to the underlying formatter if applicable
        /// </summary>
        /// <param name="prefix">Namespace Prefix</param>
        /// <param name="namespaceUri">Namespace URI</param>
        /// <returns></returns>
        protected override bool HandleNamespaceInternal(string prefix, Uri namespaceUri)
        {
            if (_formattingMapper != null)
            {
                _formattingMapper.AddNamespace(prefix, namespaceUri);
            }

            if (_formatter is INamespaceFormatter)
            {
                _writer.WriteLine(((INamespaceFormatter)_formatter).FormatNamespace(prefix, namespaceUri));
            }

            return(true);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Handles namespaces by adding them to each graph
 /// </summary>
 /// <param name="prefix">Namespace Prefix</param>
 /// <param name="namespaceUri">Namespace URI</param>
 /// <returns></returns>
 protected override bool HandleNamespaceInternal(string prefix, Uri namespaceUri)
 {
     _nsmap.AddNamespace(prefix, namespaceUri);
     return(true);
 }
 /// <summary>Creates a new instance of <see cref="TripleStoreAdapter"/></summary>
 /// <param name="store">The underlying triple store</param>
 public TripleStoreAdapter(ITripleStore store)
 {
     _store = store;
     _namespaces = new NamespaceMapper(true);
     _namespaces.AddNamespace("foaf", new Uri("http://xmlns.com/foaf/0.1/"));
 }
Ejemplo n.º 5
0
 protected override bool HandleNamespaceInternal(string prefix, Uri namespaceUri)
 {
     namespaceMapper.AddNamespace(prefix, namespaceUri);
     return(base.HandleNamespaceInternal(prefix, namespaceUri));
 }
Ejemplo n.º 6
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));
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Get column name by using qname compression and replacing special chars with underscores
        /// </summary>
        /// <param name="node">Node</param>
        /// <param name="namespaces">Namespaces</param>
        /// <returns></returns>
        private string GetColumnName(INode node, INamespaceMapper namespaces)
        {
            if (node.NodeType != NodeType.Uri)
            {
                return(null);
            }
            Uri u = ((IUriNode)node).Uri;

            String qname;

            if (!namespaces.ReduceToQName(u.AbsoluteUri, out qname))
            {
                // Issue temporary namespaces
                String tempNsPrefix = "ns" + this._nextTempID;
                String nsUri        = u.AbsoluteUri;
                if (nsUri.Contains("#"))
                {
                    //Create a Hash Namespace Uri
                    nsUri = nsUri.Substring(0, nsUri.LastIndexOf("#") + 1);
                }
                else if (nsUri.Contains("/"))
                {
                    //Create a Slash Namespace Uri
                    nsUri = nsUri.Substring(0, nsUri.LastIndexOf("/") + 1);
                }
                Uri tempNsUri;
                if (!Uri.TryCreate(nsUri, UriKind.Absolute, out tempNsUri))
                {
                    tempNsUri = u;
                }
                while (namespaces.HasNamespace(tempNsPrefix))
                {
                    this._nextTempID++;
                    tempNsPrefix = "ns" + this._nextTempID;
                }
                namespaces.AddNamespace(tempNsPrefix, tempNsUri);
                if (!namespaces.ReduceToQName(u.AbsoluteUri, out qname))
                {
                    qname = null;
                }
            }
            if (qname == null)
            {
                // Issue temporary column name
                return("entityPredicateColumn" + (++this._nextTempColumnID));
            }
            // Sanitize qname column name
            qname = qname.StartsWith("_") ? qname.Substring(1) : qname.Replace(':', '_');
            if (SparqlSpecsHelper.IsValidVarName(qname))
            {
                return(qname);
            }
            if (qname.Length == 0)
            {
                // Issue temporary column name
                return("entityPredicateColumn " + (++this._nextTempColumnID));
            }

            // Clean up illegal characters
            // First Character must be from PN_CHARS_U or a digit
            // Add a leading p for invalid first characters
            char[] cs    = qname.ToCharArray();
            char   first = cs[0];

            if (!Char.IsDigit(first) || !SparqlSpecsHelper.IsPNCharsU(first))
            {
                qname = "p" + qname;
                if (SparqlSpecsHelper.IsValidVarName(qname))
                {
                    return(qname);
                }
                cs = qname.ToCharArray();
            }
            for (int i = 1; i < cs.Length; i++)
            {
                if (i >= cs.Length - 1)
                {
                    continue;
                }
                // Subsequent Chars must be from PN_CHARS (except -) or a '.'
                // Replace invalid characters with _
                if (cs[i] == '.' || cs[i] == '-')
                {
                    cs[i] = '_';
                }
                else if (!SparqlSpecsHelper.IsPNChars(cs[i]))
                {
                    cs[i] = '_';
                }
            }
            // Trim trailing underscores
            return(new string(cs).TrimEnd('_'));
        }