<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns="http://www.springframework.org/schema/beans"
       xmlns:util="http://www.springframework.org/schema/util"
       xsi:schemaLocation="
       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
       http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd">

    <description>
        <![CDATA[
        Contains SPARQL queries for the subset of the BioPax ontology that is supported by the BioPax loader.

        http://www.w3.org/TR/rdf-sparql-query/
        http://www.biopax.org/

        The following conventions should be used by all queries, failure to do so could result in
        unexpected results by client code that processes the queries.

        The sparqlQueryValidator bean defined within biopax-queries-validator.xml should be run
        after modifications to the definitions contained within this configuration file.

        Conventions:

            1) Queries should use the prefix bindings defined within the prefixMap property of
               the jenaKnowledgeBaseFactory bean.

            2) The names of the variables that are returned from the query must be defined in java classes.        
               [See the sparqlQueryValidator bean defined within biopax-queries-validator.xml]

            3) The name of each variable returned from a query is typically the same as its corresponding
               name within the ontology, with the exception of '_' replacing '-'. 

            4) Only return the columns from a query that are required by the client code.

        The queries that are actually used by the BioPax loader are defined by the biopax-queries bean.

        You can easily test any of the queries outside of the BioPax loader by using a SPARQL GUI tool such as
        Twinkle. Just copy/paste the following prefix specifications into the Twinkle
        edit window followed by the query text. Then, load the input rdf file.
        
            PREFIX bp: <http://www.biopax.org/release/biopax-level2.owl#>
            PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
            PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

        ]]>
    </description>


    <bean id="biopax-queries_publicationXref" class="java.lang.String">
        <constructor-arg>
            <value>
                SELECT DISTINCT * WHERE {
                    ?publicationXref rdf:type bp:publicationXref
                    OPTIONAL {?publicationXref bp:ID ?ID}
                    OPTIONAL {?publicationXref bp:DB ?DB}
                }
            </value>
        </constructor-arg>
    </bean>

    <bean id="biopax-queries_physicalInteraction" class="java.lang.String">
        <constructor-arg>
            <value>
                SELECT DISTINCT ?physicalInteraction
                                ?NAME
                                ?PARTICIPANTS
                                ?XREF
                                ?EVIDENCE_CODE
                WHERE {
                    ?physicalInteraction rdf:type bp:physicalInteraction
                    OPTIONAL {?physicalInteraction bp:NAME ?NAME}
                    OPTIONAL {?physicalInteraction bp:PARTICIPANTS ?PARTICIPANTS}
                    OPTIONAL {?physicalInteraction bp:XREF ?XREF}
                    OPTIONAL {?physicalInteraction bp:EVIDENCE ?evidence}
                    OPTIONAL {?evidence bp:EVIDENCE-CODE ?EVIDENCE_CODE}
                }
            </value>
        </constructor-arg>
    </bean>

    <bean id="biopax-queries_protein" class="java.lang.String">
        <constructor-arg>
            <value>
                SELECT DISTINCT * WHERE {
                        ?protein rdf:type bp:protein
                        OPTIONAL {?protein bp:NAME ?NAME}
                        OPTIONAL {?protein bp:SHORT-NAME ?SHORT_NAME}
                        OPTIONAL {?protein bp:ORGANISM ?ORGANISM}
                        OPTIONAL {?protein bp:XREF ?XREF}
                    }
            </value>
        </constructor-arg>
    </bean>

    <bean id="biopax-queries_rna" class="java.lang.String">
        <constructor-arg>
            <value>
                SELECT DISTINCT * WHERE {
                        ?rna rdf:type bp:rna
                        OPTIONAL {?rna bp:NAME ?NAME}
                        OPTIONAL {?rna bp:SHORT-NAME ?SHORT_NAME}
                        OPTIONAL {?rna bp:ORGANISM ?ORGANISM}
                        OPTIONAL {?rna bp:XREF ?XREF}
                    }
            </value>
        </constructor-arg>
    </bean>

    <bean id="biopax-queries_dna" class="java.lang.String">
        <constructor-arg>
            <value>
                SELECT DISTINCT * WHERE {
                        ?dna rdf:type bp:dna
                        OPTIONAL {?dna bp:NAME ?NAME}
                        OPTIONAL {?dna bp:SHORT-NAME ?SHORT_NAME}
                        OPTIONAL {?dna bp:ORGANISM ?ORGANISM}
                        OPTIONAL {?dna bp:XREF ?XREF}
                    }
            </value>
        </constructor-arg>
    </bean>

    <bean id="biopax-queries_openControlledVocabulary" class="java.lang.String">
        <constructor-arg>
            <value>
                SELECT DISTINCT * WHERE {
                    ?openControlledVocabulary rdf:type bp:openControlledVocabulary
                    OPTIONAL {?openControlledVocabulary bp:TERM ?TERM}
                    OPTIONAL {?openControlledVocabulary bp:XREF ?XREF}
                }
            </value>
        </constructor-arg>
    </bean>

    <bean id="biopax-queries_unificationXref" class="java.lang.String">
        <constructor-arg>
            <value>
                SELECT DISTINCT * WHERE {
                    ?unificationXref rdf:type bp:unificationXref
                    OPTIONAL {?unificationXref bp:ID ?ID}
                    OPTIONAL {?unificationXref bp:DB ?DB}
                }
            </value>
        </constructor-arg>
    </bean>


    <bean id="biopax-queries_bioSource-Taxon" class="java.lang.String">
        <constructor-arg>
            <value>
                SELECT DISTINCT ?bioSource ?NAME ?ID WHERE {
                   ?bioSource rdf:type bp:bioSource
                    OPTIONAL {?bioSource bp:NAME ?NAME}
                    OPTIONAL {?bioSource bp:TAXON-XREF ?TAXON_XREF}
                    OPTIONAL {?TAXON_XREF bp:ID ?ID}
                }
            </value>
        </constructor-arg>
    </bean>

    <bean id="biopax-queries" class="java.util.HashMap">
        <description>
            Defines a mapping from ontology class names used by the BioPax loader to their
            corresponding SPARQL queries.

            The key name must correspond to a class name within the ontology and it
            must be the name of a variable returned by the SPARQL query that is
            pointed to by the value-ref.

            The values returned by the query for this variable must be the corresponding
            class instance's URI.
        </description>
        <constructor-arg>
            <map>
                <entry key="publicationXref" value-ref="biopax-queries_publicationXref"/>
                <entry key="physicalInteraction" value-ref="biopax-queries_physicalInteraction"/>

                <entry key="protein" value-ref="biopax-queries_protein"/>
                <entry key="rna" value-ref="biopax-queries_rna"/>
                <entry key="dna" value-ref="biopax-queries_dna"/>
                <entry key="bioSource" value-ref="biopax-queries_bioSource-Taxon"/>
                <entry key="openControlledVocabulary" value-ref="biopax-queries_openControlledVocabulary"/>
                <entry key="unificationXref" value-ref="biopax-queries_unificationXref"/>
            </map>
        </constructor-arg>
    </bean>

    <bean id="jenaKnowledgeBaseFactory" class="com.sri.iris.jena.JenaKnowledgeBaseFactory">
        <property name="prefixMap">
            <map>
                <entry key="rdf" value="http://www.w3.org/1999/02/22-rdf-syntax-ns#"/>
                <entry key="rdfs" value="http://www.w3.org/2000/01/rdf-schema#"/>
                <entry key="xsd" value="http://www.w3.org/2001/XMLSchema#"/>
                <entry key="owl" value="http://www.w3.org/2002/07/owl#"/>
                <entry key="bp" value="http://www.biopax.org/release/biopax-level2.owl#"/>
            </map>
        </property>
        <property name="ontologyFiles" value="file:${ontology-files-dir}/biopax-level2.owl"/>
        <property name="ontModelSpec">
            <util:constant static-field="com.hp.hpl.jena.ontology.OntModelSpec.OWL_DL_MEM"/>
        </property>
    </bean>

</beans>