Extracting the actual value from sparql results

996 views Asked by At

i am using dotnetrdf to write sparql query to get the type, id and explain attributes of an actuator saved in my ontology. im using the following select query.

      "PREFIX AP0: <http://www.semanticweb.org/faiza/ontologies/2014/10/ActuatorProvider#> " +
      "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>" +
      "PREFIX owl: <http://www.w3.org/2002/07/owl#>" +
      "PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>" +
      "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>" +
    "SELECT *"+ 
    "WHERE {"+
     "?Name rdf:type AP0:Actuating_Device."+
     "?Name AP0:ActuatorID ?id."+
     "?Name AP0:ActuatorExplain ?Explain."+
     "?Name AP0:AcuatorCode "txtActuatorID.Text"}"

The results are displayed using this method

 public void datadisplay1(IEnumerable<string> variables, SparqlResultSet srs)
        {
            dataGridView1.Columns.Clear();
            int vn = 0;
            foreach (string v in variables)
            {
                dataGridView1.Columns.Add(v, v); ;
                this.dataGridView1.Columns[vn].Width = 300;
                  vn++;
            }


            foreach (SparqlResult r in srs)
            {
                int i = 0;
                object[] items = new object[vn];

                foreach (string s in variables)
                {

                    items[i++] = r.Value(s);

                }
                dataGridView1.Rows.Add(items );
                            }

here is my owl file

<?xml version="1.0"?>


<!DOCTYPE rdf:RDF [
    <!ENTITY owl "http://www.w3.org/2002/07/owl#" >
    <!ENTITY xsd "http://www.w3.org/2001/XMLSchema#" >
    <!ENTITY rdfs "http://www.w3.org/2000/01/rdf-schema#" >
    <!ENTITY ace_lexicon "http://attempto.ifi.uzh.ch/ace_lexicon#" >
    <!ENTITY rdf "http://www.w3.org/1999/02/22-rdf-syntax-ns#" >
    <!ENTITY AP0 "http://www.semanticweb.org/faiza/ontologies/2014/10/ActuatorProvider" >
    <!ENTITY ActuatorProvider "http://www.semanticweb.org/faiza/ontologies/2014/10/ActuatorProvider#" >
]>


<rdf:RDF xmlns="&AP0;#"
     xml:base="http://www.semanticweb.org/faiza/ontologies/2014/10/ActuatorProvider"
     xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
     xmlns:owl="http://www.w3.org/2002/07/owl#"
     xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
     xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
     xmlns:AP0="http://www.semanticweb.org/faiza/ontologies/2014/10/ActuatorProvider"
     xmlns:ActuatorProvider="&AP0;#"
     xmlns:ace_lexicon="http://attempto.ifi.uzh.ch/ace_lexicon#">
    <owl:Ontology rdf:about="http://www.semanticweb.org/faiza/ontologies/2014/10/ActuatorProvider"/>



    <!-- 
    ///////////////////////////////////////////////////////////////////////////////////////
    //
    // Annotation properties
    //
    ///////////////////////////////////////////////////////////////////////////////////////
     -->




    <!-- http://attempto.ifi.uzh.ch/ace_lexicon#CN_pl -->

    <owl:AnnotationProperty rdf:about="&ace_lexicon;CN_pl"/>



    <!-- http://attempto.ifi.uzh.ch/ace_lexicon#CN_sg -->

    <owl:AnnotationProperty rdf:about="&ace_lexicon;CN_sg"/>



    <!-- http://attempto.ifi.uzh.ch/ace_lexicon#PN_sg -->

    <owl:AnnotationProperty rdf:about="&ace_lexicon;PN_sg"/>



    <!-- http://attempto.ifi.uzh.ch/ace_lexicon#TV_pl -->

    <owl:AnnotationProperty rdf:about="&ace_lexicon;TV_pl"/>



    <!-- http://attempto.ifi.uzh.ch/ace_lexicon#TV_sg -->

    <owl:AnnotationProperty rdf:about="&ace_lexicon;TV_sg"/>



    <!-- http://attempto.ifi.uzh.ch/ace_lexicon#TV_vbg -->

    <owl:AnnotationProperty rdf:about="&ace_lexicon;TV_vbg"/>



    <!-- 
    ///////////////////////////////////////////////////////////////////////////////////////
    //
    // Object Properties
    //
    ///////////////////////////////////////////////////////////////////////////////////////
     -->




    <!-- http://www.semanticweb.org/faiza/ontologies/2014/10/ActuatorProvider#ConnectsTo -->

    <owl:ObjectProperty rdf:about="&AP0;#ConnectsTo">
        <ace_lexicon:TV_pl>ConnectsTo</ace_lexicon:TV_pl>
        <ace_lexicon:TV_sg>ConnectsToes</ace_lexicon:TV_sg>
        <ace_lexicon:TV_vbg>ConnectsToed</ace_lexicon:TV_vbg>
    </owl:ObjectProperty>



    <!-- http://www.semanticweb.org/faiza/ontologies/2014/10/ActuatorProvider#Perform -->

    <owl:ObjectProperty rdf:about="&AP0;#Perform">
        <ace_lexicon:TV_pl>Perform</ace_lexicon:TV_pl>
        <ace_lexicon:TV_vbg>Performed</ace_lexicon:TV_vbg>
        <ace_lexicon:TV_sg>Performs</ace_lexicon:TV_sg>
        <rdfs:domain rdf:resource="&AP0;#Actuator_Support_Toolbox"/>
        <rdfs:range rdf:resource="&AP0;#Management"/>
    </owl:ObjectProperty>



    <!-- http://www.semanticweb.org/faiza/ontologies/2014/10/ActuatorProvider#Provide -->

    <owl:ObjectProperty rdf:about="&AP0;#Provide">
        <ace_lexicon:TV_sg>Provides</ace_lexicon:TV_sg>
        <ace_lexicon:TV_pl>Provide</ace_lexicon:TV_pl>
        <ace_lexicon:TV_vbg>Provided</ace_lexicon:TV_vbg>
        <rdfs:range rdf:resource="&AP0;#APServices"/>
        <rdfs:domain rdf:resource="&AP0;#Actuator_Service_Provider"/>
    </owl:ObjectProperty>



    <!-- http://www.semanticweb.org/faiza/ontologies/2014/10/ActuatorProvider#Use -->

    <owl:ObjectProperty rdf:about="&AP0;#Use">
        <ace_lexicon:TV_pl>Use</ace_lexicon:TV_pl>
        <ace_lexicon:TV_vbg>Used</ace_lexicon:TV_vbg>
        <ace_lexicon:TV_sg>Uses</ace_lexicon:TV_sg>
    </owl:ObjectProperty>



    <!-- http://www.semanticweb.org/faiza/ontologies/2014/10/ActuatorProvider#hasState -->

    <owl:ObjectProperty rdf:about="&AP0;#hasState">
        <rdf:type rdf:resource="&owl;FunctionalProperty"/>
        <ace_lexicon:TV_pl>hasState</ace_lexicon:TV_pl>
        <ace_lexicon:TV_vbg>hasStated</ace_lexicon:TV_vbg>
        <ace_lexicon:TV_sg>hasStates</ace_lexicon:TV_sg>
        <rdfs:range rdf:resource="&AP0;#Actuator_State"/>
        <rdfs:domain rdf:resource="&AP0;#Device"/>
    </owl:ObjectProperty>



    <!-- 
    ///////////////////////////////////////////////////////////////////////////////////////
    //
    // Data properties
    //
    ///////////////////////////////////////////////////////////////////////////////////////
     -->




    <!-- http://www.semanticweb.org/faiza/ontologies/2014/10/ActuatorProvider#ActuatorCode -->

    <owl:DatatypeProperty rdf:about="&AP0;#ActuatorCode">
        <ace_lexicon:TV_sg>ActuatorCodes</ace_lexicon:TV_sg>
        <ace_lexicon:TV_pl>ActuatorCode</ace_lexicon:TV_pl>
        <ace_lexicon:TV_vbg>ActuatorCoded</ace_lexicon:TV_vbg>
        <rdfs:domain rdf:resource="&AP0;#Actuating_Device"/>
        <rdfs:range rdf:resource="&xsd;integer"/>
    </owl:DatatypeProperty>



    <!-- http://www.semanticweb.org/faiza/ontologies/2014/10/ActuatorProvider#ActuatorExplain -->

    <owl:DatatypeProperty rdf:about="&AP0;#ActuatorExplain">
        <ace_lexicon:TV_vbg>ActuatorExplained</ace_lexicon:TV_vbg>
        <ace_lexicon:TV_sg>ActuatorExplains</ace_lexicon:TV_sg>
        <ace_lexicon:TV_pl>ActuatorExplain</ace_lexicon:TV_pl>
        <rdfs:domain rdf:resource="&AP0;#Actuating_Device"/>
        <rdfs:range rdf:resource="&xsd;string"/>
        <rdfs:subPropertyOf rdf:resource="&owl;topDataProperty"/>
    </owl:DatatypeProperty>



    <!-- http://www.semanticweb.org/faiza/ontologies/2014/10/ActuatorProvider#ActuatorID -->

    <owl:DatatypeProperty rdf:about="&AP0;#ActuatorID">
        <ace_lexicon:TV_pl>ActuatorID</ace_lexicon:TV_pl>
        <ace_lexicon:TV_vbg>ActuatorIDed</ace_lexicon:TV_vbg>
        <ace_lexicon:TV_sg>ActuatorIDs</ace_lexicon:TV_sg>
        <rdfs:domain rdf:resource="&AP0;#Actuating_Device"/>
        <rdfs:range rdf:resource="&xsd;string"/>
    </owl:DatatypeProperty>



    <!-- http://www.semanticweb.org/faiza/ontologies/2014/10/ActuatorProvider#ActuatorName -->

    <owl:DatatypeProperty rdf:about="&AP0;#ActuatorName">
        <ace_lexicon:TV_pl>ActuatorName</ace_lexicon:TV_pl>
        <ace_lexicon:TV_vbg>ActuatorNamed</ace_lexicon:TV_vbg>
        <ace_lexicon:TV_sg>ActuatorNames</ace_lexicon:TV_sg>
        <rdfs:domain rdf:resource="&AP0;#Actuating_Device"/>
        <rdfs:range rdf:resource="&xsd;string"/>
    </owl:DatatypeProperty>



    <!-- http://www.semanticweb.org/faiza/ontologies/2014/10/ActuatorProvider#MiddlewareCode -->

    <owl:DatatypeProperty rdf:about="&AP0;#MiddlewareCode">
        <ace_lexicon:TV_vbg>MiddlewareCoded</ace_lexicon:TV_vbg>
        <ace_lexicon:TV_pl>MiddlewareCode</ace_lexicon:TV_pl>
        <ace_lexicon:TV_sg>MiddlewareCodes</ace_lexicon:TV_sg>
        <rdfs:domain rdf:resource="&AP0;#Actuator_Middleware"/>
        <rdfs:range rdf:resource="&xsd;integer"/>
    </owl:DatatypeProperty>



    <!-- http://www.semanticweb.org/faiza/ontologies/2014/10/ActuatorProvider#MiddlewareID -->

    <owl:DatatypeProperty rdf:about="&AP0;#MiddlewareID">
        <ace_lexicon:TV_sg>MiddlewareIDs</ace_lexicon:TV_sg>
        <ace_lexicon:TV_pl>MiddlewareID</ace_lexicon:TV_pl>
        <ace_lexicon:TV_vbg>MiddlewareIDed</ace_lexicon:TV_vbg>
        <rdfs:domain rdf:resource="&AP0;#Actuator_Middleware"/>
        <rdfs:range rdf:resource="&xsd;string"/>
    </owl:DatatypeProperty>



    <!-- http://www.semanticweb.org/faiza/ontologies/2014/10/ActuatorProvider#MiddlewareRight -->

    <owl:DatatypeProperty rdf:about="&AP0;#MiddlewareRight">
        <ace_lexicon:TV_vbg>MiddlewareRighted</ace_lexicon:TV_vbg>
        <ace_lexicon:TV_sg>MiddlewareRights</ace_lexicon:TV_sg>
        <ace_lexicon:TV_pl>MiddlewareRight</ace_lexicon:TV_pl>
        <rdfs:domain rdf:resource="&AP0;#Actuator_Middleware"/>
        <rdfs:range rdf:resource="&xsd;boolean"/>
    </owl:DatatypeProperty>



    <!-- http://www.semanticweb.org/faiza/ontologies/2014/10/ActuatorProvider#PowerConsumption -->

    <owl:DatatypeProperty rdf:about="&AP0;#PowerConsumption">
        <ace_lexicon:TV_vbg>PowerConsumptioned</ace_lexicon:TV_vbg>
        <ace_lexicon:TV_pl>PowerConsumption</ace_lexicon:TV_pl>
        <ace_lexicon:TV_sg>PowerConsumptions</ace_lexicon:TV_sg>
        <rdfs:domain rdf:resource="&AP0;#Actuating_Device"/>
        <rdfs:range rdf:resource="&xsd;integer"/>
    </owl:DatatypeProperty>



    <!-- 
    ///////////////////////////////////////////////////////////////////////////////////////
    //
    // Classes
    //
    ///////////////////////////////////////////////////////////////////////////////////////
     -->




    <!-- http://www.semanticweb.org/faiza/ontologies/2014/10/ActuatorProvider#APServices -->

    <owl:Class rdf:about="&AP0;#APServices">
        <ace_lexicon:CN_pl>APServiceses</ace_lexicon:CN_pl>
        <ace_lexicon:CN_sg>APServices</ace_lexicon:CN_sg>
    </owl:Class>



    <!-- http://www.semanticweb.org/faiza/ontologies/2014/10/ActuatorProvider#Actuating_Device -->

    <owl:Class rdf:about="&AP0;#Actuating_Device">
        <rdfs:subClassOf rdf:resource="&AP0;#Device"/>
        <rdfs:subClassOf>
            <owl:Restriction>
                <owl:onProperty rdf:resource="&AP0;#hasState"/>
                <owl:onClass rdf:resource="&AP0;#Actuator_State"/>
                <owl:qualifiedCardinality rdf:datatype="&xsd;nonNegativeInteger">1</owl:qualifiedCardinality>
            </owl:Restriction>
        </rdfs:subClassOf>
        <ace_lexicon:CN_sg>Actuating_Device</ace_lexicon:CN_sg>
        <ace_lexicon:CN_pl>Actuating_Devices</ace_lexicon:CN_pl>
    </owl:Class>



    <!-- http://www.semanticweb.org/faiza/ontologies/2014/10/ActuatorProvider#Actuator_Content_Service -->

    <owl:Class rdf:about="&AP0;#Actuator_Content_Service">
        <rdfs:subClassOf rdf:resource="&AP0;#APServices"/>
        <ace_lexicon:CN_pl>Actuator_Content_Services</ace_lexicon:CN_pl>
        <ace_lexicon:CN_sg>Actuator_Content_Service</ace_lexicon:CN_sg>
    </owl:Class>



    <!-- http://www.semanticweb.org/faiza/ontologies/2014/10/ActuatorProvider#Actuator_Control_Service -->

    <owl:Class rdf:about="&AP0;#Actuator_Control_Service">
        <rdfs:subClassOf rdf:resource="&AP0;#APServices"/>
        <ace_lexicon:CN_sg>Actuator_Control_Service</ace_lexicon:CN_sg>
        <ace_lexicon:CN_pl>Actuator_Control_Services</ace_lexicon:CN_pl>
    </owl:Class>



    <!-- http://www.semanticweb.org/faiza/ontologies/2014/10/ActuatorProvider#Actuator_Info_Management -->

    <owl:Class rdf:about="&AP0;#Actuator_Info_Management">
        <rdfs:subClassOf rdf:resource="&AP0;#Management"/>
        <rdfs:subClassOf>
            <owl:Restriction>
                <owl:onProperty rdf:resource="&AP0;#Use"/>
                <owl:someValuesFrom rdf:resource="&AP0;#Actuator_Content_Service"/>
            </owl:Restriction>
        </rdfs:subClassOf>
        <ace_lexicon:CN_sg>Actuator_Info_Management</ace_lexicon:CN_sg>
        <ace_lexicon:CN_pl>Actuator_Info_Managements</ace_lexicon:CN_pl>
    </owl:Class>



    <!-- http://www.semanticweb.org/faiza/ontologies/2014/10/ActuatorProvider#Actuator_Middleware -->

    <owl:Class rdf:about="&AP0;#Actuator_Middleware">
        <rdfs:subClassOf>
            <owl:Restriction>
                <owl:onProperty rdf:resource="&AP0;#ConnectsTo"/>
                <owl:onClass rdf:resource="&AP0;#Actuator_Service_Provider"/>
                <owl:maxQualifiedCardinality rdf:datatype="&xsd;nonNegativeInteger">1</owl:maxQualifiedCardinality>
            </owl:Restriction>
        </rdfs:subClassOf>
        <rdfs:subClassOf>
            <owl:Restriction>
                <owl:onProperty rdf:resource="&AP0;#Use"/>
                <owl:someValuesFrom rdf:resource="&AP0;#Actuator_Control_Service"/>
            </owl:Restriction>
        </rdfs:subClassOf>
        <ace_lexicon:CN_sg>Actuator_Middleware</ace_lexicon:CN_sg>
        <ace_lexicon:CN_pl>Actuator_Middlewares</ace_lexicon:CN_pl>
    </owl:Class>



    <!-- http://www.semanticweb.org/faiza/ontologies/2014/10/ActuatorProvider#Actuator_Provider_Service -->

    <owl:Class rdf:about="&AP0;#Actuator_Provider_Service">
        <rdfs:subClassOf rdf:resource="&AP0;#APServices"/>
        <ace_lexicon:CN_sg>Actuator_Provider_Service</ace_lexicon:CN_sg>
        <ace_lexicon:CN_pl>Actuator_Provider_Services</ace_lexicon:CN_pl>
    </owl:Class>



    <!-- http://www.semanticweb.org/faiza/ontologies/2014/10/ActuatorProvider#Actuator_Service_Provider -->

    <owl:Class rdf:about="&AP0;#Actuator_Service_Provider">
        <rdfs:subClassOf>
            <owl:Restriction>
                <owl:onProperty rdf:resource="&AP0;#ConnectsTo"/>
                <owl:someValuesFrom rdf:resource="&AP0;#Actuator_Support_Toolbox"/>
            </owl:Restriction>
        </rdfs:subClassOf>
        <ace_lexicon:CN_sg>Actuator_Service_Provider</ace_lexicon:CN_sg>
        <ace_lexicon:CN_pl>Actuator_Service_Providers</ace_lexicon:CN_pl>
    </owl:Class>



    <!-- http://www.semanticweb.org/faiza/ontologies/2014/10/ActuatorProvider#Actuator_State -->

    <owl:Class rdf:about="&AP0;#Actuator_State">
        <ace_lexicon:CN_sg>Actuator_State</ace_lexicon:CN_sg>
        <ace_lexicon:CN_pl>Actuator_States</ace_lexicon:CN_pl>
    </owl:Class>



    <!-- http://www.semanticweb.org/faiza/ontologies/2014/10/ActuatorProvider#Actuator_Support_Toolbox -->

    <owl:Class rdf:about="&AP0;#Actuator_Support_Toolbox">
        <rdfs:subClassOf>
            <owl:Restriction>
                <owl:onProperty rdf:resource="&AP0;#Perform"/>
                <owl:someValuesFrom rdf:resource="&AP0;#Management"/>
            </owl:Restriction>
        </rdfs:subClassOf>
        <ace_lexicon:CN_pl>Actuator_Support_Toolboxes</ace_lexicon:CN_pl>
        <ace_lexicon:CN_sg>Actuator_Support_Toolbox</ace_lexicon:CN_sg>
    </owl:Class>



    <!-- http://www.semanticweb.org/faiza/ontologies/2014/10/ActuatorProvider#Device -->

    <owl:Class rdf:about="&AP0;#Device">
        <rdfs:subClassOf>
            <owl:Restriction>
                <owl:onProperty rdf:resource="&AP0;#hasState"/>
                <owl:onClass rdf:resource="&AP0;#Actuator_State"/>
                <owl:qualifiedCardinality rdf:datatype="&xsd;nonNegativeInteger">1</owl:qualifiedCardinality>
            </owl:Restriction>
        </rdfs:subClassOf>
        <rdfs:subClassOf>
            <owl:Restriction>
                <owl:onProperty rdf:resource="&AP0;#ConnectsTo"/>
                <owl:onClass rdf:resource="&AP0;#Actuator_Middleware"/>
                <owl:maxQualifiedCardinality rdf:datatype="&xsd;nonNegativeInteger">1</owl:maxQualifiedCardinality>
            </owl:Restriction>
        </rdfs:subClassOf>
        <ace_lexicon:CN_sg>Device</ace_lexicon:CN_sg>
        <ace_lexicon:CN_pl>Devices</ace_lexicon:CN_pl>
    </owl:Class>



    <!-- http://www.semanticweb.org/faiza/ontologies/2014/10/ActuatorProvider#Management -->

    <owl:Class rdf:about="&AP0;#Management">
        <ace_lexicon:CN_sg>Management</ace_lexicon:CN_sg>
        <ace_lexicon:CN_pl>Managements</ace_lexicon:CN_pl>
    </owl:Class>



    <!-- http://www.semanticweb.org/faiza/ontologies/2014/10/ActuatorProvider#Middleware_Access_Management -->

    <owl:Class rdf:about="&AP0;#Middleware_Access_Management">
        <rdfs:subClassOf rdf:resource="&AP0;#Management"/>
        <rdfs:subClassOf>
            <owl:Restriction>
                <owl:onProperty rdf:resource="&AP0;#Use"/>
                <owl:someValuesFrom rdf:resource="&AP0;#Actuator_Content_Service"/>
            </owl:Restriction>
        </rdfs:subClassOf>
        <ace_lexicon:CN_pl>Middleware_Access_Managements</ace_lexicon:CN_pl>
        <ace_lexicon:CN_sg>Middleware_Access_Management</ace_lexicon:CN_sg>
    </owl:Class>



    <!-- http://www.semanticweb.org/faiza/ontologies/2014/10/ActuatorProvider#Service_Info_Management -->

    <owl:Class rdf:about="&AP0;#Service_Info_Management">
        <rdfs:subClassOf rdf:resource="&AP0;#Management"/>
        <ace_lexicon:CN_sg>Service_Info_Management</ace_lexicon:CN_sg>
        <ace_lexicon:CN_pl>Service_Info_Managements</ace_lexicon:CN_pl>
    </owl:Class>



    <!-- 
    ///////////////////////////////////////////////////////////////////////////////////////
    //
    // Individuals
    //
    ///////////////////////////////////////////////////////////////////////////////////////
     -->




    <!-- http://www.semanticweb.org/faiza/ontologies/2014/10/ActuatorProvider#ActuatingDevice1 -->

    <owl:NamedIndividual rdf:about="&AP0;#ActuatingDevice1">
        <rdf:type rdf:resource="&AP0;#Actuating_Device"/>
        <ActuatorName rdf:datatype="&xsd;string">&quot;Fan&quot;</ActuatorName>
        <ActuatorID rdf:datatype="&xsd;string">&quot;SD01&quot;</ActuatorID>
        <ActuatorExplain rdf:datatype="&xsd;string">&quot;TemperatureControl&quot;</ActuatorExplain>
        <ActuatorCode rdf:datatype="&xsd;integer">1</ActuatorCode>
        <PowerConsumption rdf:datatype="&xsd;integer">400</PowerConsumption>
        <ace_lexicon:PN_sg>ActuatingDevice1</ace_lexicon:PN_sg>
        <ConnectsTo rdf:resource="&AP0;#ActuatorMiddleware1"/>
        <hasState rdf:resource="&AP0;#Offline"/>
    </owl:NamedIndividual>



    <!-- http://www.semanticweb.org/faiza/ontologies/2014/10/ActuatorProvider#ActuatingDevice2 -->

    <owl:NamedIndividual rdf:about="&AP0;#ActuatingDevice2">
        <rdf:type rdf:resource="&AP0;#Actuating_Device"/>
        <ActuatorExplain rdf:datatype="&xsd;string">&quot;AirConditioner&quot;</ActuatorExplain>
        <ActuatorID rdf:datatype="&xsd;string">&quot;DS02&quot;</ActuatorID>
        <ActuatorName rdf:datatype="&xsd;string">&quot;LabConditioner&quot;</ActuatorName>
        <PowerConsumption rdf:datatype="&xsd;integer">1300</PowerConsumption>
        <ActuatorCode rdf:datatype="&xsd;integer">2</ActuatorCode>
        <ace_lexicon:PN_sg>ActuatingDevice2</ace_lexicon:PN_sg>
        <ConnectsTo rdf:resource="&AP0;#ActuatorMiddleware1"/>
        <hasState rdf:resource="&AP0;#Online"/>
    </owl:NamedIndividual>



    <!-- http://www.semanticweb.org/faiza/ontologies/2014/10/ActuatorProvider#ActuatingDevice3 -->

    <owl:NamedIndividual rdf:about="&AP0;#ActuatingDevice3">
        <rdf:type rdf:resource="&AP0;#Actuating_Device"/>
        <ace_lexicon:PN_sg>ActuatingDevice3</ace_lexicon:PN_sg>
        <ConnectsTo rdf:resource="&AP0;#ActuatorMiddleware2"/>
        <hasState rdf:resource="&AP0;#Waiting"/>
    </owl:NamedIndividual>



    <!-- http://www.semanticweb.org/faiza/ontologies/2014/10/ActuatorProvider#ActuatorMiddleware1 -->

    <owl:NamedIndividual rdf:about="&AP0;#ActuatorMiddleware1">
        <rdf:type rdf:resource="&AP0;#Actuator_Middleware"/>
        <MiddlewareID rdf:datatype="&xsd;string">&quot;MW101&quot;</MiddlewareID>
        <MiddlewareCode rdf:datatype="&xsd;integer">1</MiddlewareCode>
        <MiddlewareRight rdf:datatype="&xsd;boolean">false</MiddlewareRight>
        <ace_lexicon:PN_sg>ActuatorMiddleware1</ace_lexicon:PN_sg>
        <ConnectsTo rdf:resource="&AP0;#ActuatorServiceProvider1"/>
        <Use rdf:resource="&AP0;#ControlService1"/>
    </owl:NamedIndividual>



    <!-- http://www.semanticweb.org/faiza/ontologies/2014/10/ActuatorProvider#ActuatorMiddleware2 -->

    <owl:NamedIndividual rdf:about="&AP0;#ActuatorMiddleware2">
        <rdf:type rdf:resource="&AP0;#Actuator_Middleware"/>
        <MiddlewareID rdf:datatype="&xsd;string">&quot;MW102&quot;</MiddlewareID>
        <MiddlewareCode rdf:datatype="&xsd;integer">2</MiddlewareCode>
        <MiddlewareRight rdf:datatype="&xsd;boolean">true</MiddlewareRight>
        <ace_lexicon:PN_sg>ActuatorMiddleware2</ace_lexicon:PN_sg>
        <ConnectsTo rdf:resource="&AP0;#ActuatorServiceProvider1"/>
    </owl:NamedIndividual>



    <!-- http://www.semanticweb.org/faiza/ontologies/2014/10/ActuatorProvider#ActuatorServiceProvider1 -->

    <owl:NamedIndividual rdf:about="&AP0;#ActuatorServiceProvider1">
        <rdf:type rdf:resource="&AP0;#Actuator_Service_Provider"/>
        <ace_lexicon:PN_sg>ActuatorServiceProvider1</ace_lexicon:PN_sg>
        <ConnectsTo rdf:resource="&AP0;#ActuatorSupportToolbox1"/>
    </owl:NamedIndividual>



    <!-- http://www.semanticweb.org/faiza/ontologies/2014/10/ActuatorProvider#ActuatorSupportToolbox1 -->

    <owl:NamedIndividual rdf:about="&AP0;#ActuatorSupportToolbox1">
        <rdf:type rdf:resource="&AP0;#Actuator_Support_Toolbox"/>
        <ace_lexicon:PN_sg>ActuatorSupportToolbox1</ace_lexicon:PN_sg>
        <Perform rdf:resource="&AP0;#Management1"/>
    </owl:NamedIndividual>



    <!-- http://www.semanticweb.org/faiza/ontologies/2014/10/ActuatorProvider#ControlService1 -->

    <owl:NamedIndividual rdf:about="&AP0;#ControlService1">
        <ace_lexicon:PN_sg>ControlService1</ace_lexicon:PN_sg>
    </owl:NamedIndividual>



    <!-- http://www.semanticweb.org/faiza/ontologies/2014/10/ActuatorProvider#Management1 -->

    <owl:NamedIndividual rdf:about="&AP0;#Management1">
        <ace_lexicon:PN_sg>Management1</ace_lexicon:PN_sg>
    </owl:NamedIndividual>



    <!-- http://www.semanticweb.org/faiza/ontologies/2014/10/ActuatorProvider#Offline -->

    <owl:NamedIndividual rdf:about="&AP0;#Offline">
        <rdf:type rdf:resource="&AP0;#Actuator_State"/>
        <ace_lexicon:PN_sg>Offline</ace_lexicon:PN_sg>
    </owl:NamedIndividual>



    <!-- http://www.semanticweb.org/faiza/ontologies/2014/10/ActuatorProvider#Online -->

    <owl:NamedIndividual rdf:about="&AP0;#Online">
        <rdf:type rdf:resource="&AP0;#Actuator_State"/>
        <ace_lexicon:PN_sg>Online</ace_lexicon:PN_sg>
    </owl:NamedIndividual>



    <!-- http://www.semanticweb.org/faiza/ontologies/2014/10/ActuatorProvider#Waiting -->

    <owl:NamedIndividual rdf:about="&AP0;#Waiting">
        <rdf:type rdf:resource="&AP0;#Actuator_State"/>
        <ace_lexicon:PN_sg>Waiting</ace_lexicon:PN_sg>
    </owl:NamedIndividual>
</rdf:RDF>   

Im using a gridview in c# to display the results in. Its giving me the results in this form

http://www.semanticweb.org/faiza/ontologies/2014/10/ActuatorProvider#ActuatingDevice1
TemperatureControl^^http://www.w3.org/2001/XMLSchema#anyURI
SD01^^http://www.w3.org/2001/XMLSchema#anyURI

How can i remove the URI from the results.

3

There are 3 answers

1
RobV On

Well you haven't shown a complete example so we can't tell how you display the SPARQL results so it is hard to answer for your specific problem (because you haven't stated one!). However I can attempt to provide some general pointers.

The data you are seeing is the full form of the INode instances that occur in each column so the first thing you need to do if you want to access only parts of the value is get as the actual node. This can be done in several ways:

//Assuming your result row is in a variable r

//With Named Indexing
INode value = r["var"];

//With Indexing
INode value = r[0];

//With method
INode value = r.Value("var");

Pick whichever is most suitable for your use case, once you have the node we can then check what kind of node it is and act accordingly:

String text;
switch (value.NodeType)
{
  case NodeType.Literal:
    // Cast to more specific ILiteralNode in order to extract just the text
    // excluding the data type or language specifier if present
    ILiteralNode lit = (ILiteralNode)value;
    text = lit.Value;    
    break;

  case NodeType.Uri:
    // Case to more specific IUriNode in order to extract final segment of URI
    IUriNode uri = (IUriNode)value;

    // Depending on the URI format this might be in the Fragment, 
    // the last Path Segment or just the URI
    text = !String.IsNullOrEmpty(uri.Uri.Fragment) ? uri.Uri.Fragment : (uri.Uri.Segments.Length > 0 ? uri.Uri.Segments[uri.Uri.Segments.Length - 1] : uri.Uri.ToString());
    break;

  default:
    // For anything else default to ToString()
    text = value.ToString();
}

// Now do what you want with the text

You may need to encapsulate this in a reusable class/method depending on where and how you need to invoke it.

Note that if you are binding it to some kind of control in a GUI application then there are usually ways to customise how the data is presented while maintaining the actual data under the hood.

0
faiza On

I got the answer using the following in my query

SELECT ?ind (str(?Name) as ?name) (str(?Explain)as ?explain) (str(?id) as ?actid)

WHERE {.....}.
0
alelom On

Adding what I believe to be the best solution:
just use .AsValuedNode(), and then AsInteger() or any other function that gives you your preferred value type, e.g.:

//Assuming we have a Node in the variable n already
IValuedNode value = n.AsValuedNode();

//Get the integer value
int i = value.AsInteger();

I believe to be significantly better than the switch case in @RobV's answer (kudos to that answer though, as it led me in the right direction).