1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867
|
<?xml version = "1.0"?>
<!DOCTYPE stylesheet [
<!ENTITY oboInOwl "http://www.geneontology.org/formats/oboInOwl#">
<!ENTITY oboContent "http://purl.org/obo/owl/">
<!ENTITY oban "http://purl.org/obo/oban/">
<!ENTITY xref "http://purl.org/obo/owl/">
<!ENTITY xsd "http://www.w3.org/2001/XMLSchema#">
<!ENTITY owl "http://www.w3.org/2002/07/owl#">
]>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
xmlns:oban="http://purl.org/obo/oban/"
xmlns:owl="http://www.w3.org/2002/07/owl#"
xmlns:oboInOwl="&oboInOwl;"
xmlns:oboContent="&oboContent;"
>
<!-- *********************************************** -->
<!-- Imports -->
<!-- *********************************************** -->
<!-- *********************************************** -->
<!-- Parameters -->
<!-- *********************************************** -->
<xsl:param name="localid_prefix"/>
<xsl:param name="xmlbase_relative"/>
<!-- *********************************************** -->
<!-- XML -->
<!-- *********************************************** -->
<xsl:output indent="yes" method="xml"/>
<!-- *********************************************** -->
<!-- Indexes -->
<!-- *********************************************** -->
<xsl:key name="k_idspace" match="obo/header/idspace" use="local"/>
<xsl:key name="k_instance" match="obo/instance" use="id"/>
<xsl:key name="k_relation" match="obo/typedef" use="id"/>
<!-- *********************************************** -->
<!-- block passthru -->
<!-- *********************************************** -->
<xsl:template match="text()|@*">
</xsl:template>
<xsl:variable name="default_idspace">
<xsl:choose>
<xsl:when test="substring-before(//obo/term[1]/id,':')">
<xsl:value-of select="substring-before(//obo/term[1]/id,':')"/>
</xsl:when>
<xsl:when test="substring-before(//obo/typedef[1]/id,':')">
<xsl:value-of select="substring-before(//obo/typedef[1]/id,':')"/>
</xsl:when>
<xsl:when test="substring-before(//obo/instance[1]/id,':')">
<xsl:value-of select="substring-before(//obo/instance[1]/id,':')"/>
</xsl:when>
<xsl:otherwise>
<xsl:text>obo</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="xmlbase">
<xsl:choose>
<xsl:when test="key('k_idspace','_base')">
<xsl:value-of select="key('k_idspace','_base')/global"/>
</xsl:when>
<xsl:otherwise>
<xsl:text>&oboContent;</xsl:text>
<!-- ontology must have unique xml base for imports
using the ID space seems to have problems, for example with bridging ontologies:
an xp ontology may have classes with idspace GO, but may be downloaded from somewhere else.
For now we use the file path, but there is no guarantee this is dereferenceable (use 303s?)
In future, consider a default-idspace tag
See also thread " Calling the rdf file an ontology?", july11 2007, semantic-web list
-->
<xsl:choose>
<xsl:when test="$xmlbase_relative">
<xsl:value-of select="$xmlbase_relative"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="substring-before(*/source/source_path,'.')"/>
</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<!-- *********************************************** -->
<!-- Top level -->
<!-- *********************************************** -->
<xsl:template match="/">
<rdf:RDF
xmlns="&oboContent;"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
xmlns:owl="http://www.w3.org/2002/07/owl#"
xmlns:xsd="&xsd;"
xmlns:oboInOwl="&oboInOwl;"
xmlns:oboContent="&oboContent;"
xml:base="{$xmlbase}"
>
<xsl:comment>
<xsl:text>oboInOwl meta-model - we must declare this here, otherwise the ontology will be OWL-Full unless we import &oboInOwl;</xsl:text>
</xsl:comment>
<owl:AnnotationProperty rdf:about="&oboInOwl;hasAlternativeId"/>
<owl:AnnotationProperty rdf:about="&oboInOwl;hasDate"/>
<owl:AnnotationProperty rdf:about="&oboInOwl;hasVersion"/>
<owl:AnnotationProperty rdf:about="&oboInOwl;hasDbXref"/>
<owl:AnnotationProperty rdf:about="&oboInOwl;hasDefaultNamespace"/>
<owl:AnnotationProperty rdf:about="&oboInOwl;hasOBONamespace"/>
<owl:AnnotationProperty rdf:about="&oboInOwl;hasDefinition"/>
<owl:AnnotationProperty rdf:about="&oboInOwl;hasSynonym"/>
<owl:AnnotationProperty rdf:about="&oboInOwl;hasExactSynonym"/>
<owl:AnnotationProperty rdf:about="&oboInOwl;hasNarrowSynonym"/>
<owl:AnnotationProperty rdf:about="&oboInOwl;hasBroadSynonym"/>
<owl:AnnotationProperty rdf:about="&oboInOwl;hasRelatedSynonym"/>
<owl:AnnotationProperty rdf:about="&oboInOwl;hasSynonymType"/>
<owl:AnnotationProperty rdf:about="&oboInOwl;hasSubset"/>
<owl:AnnotationProperty rdf:about="&oboInOwl;hasURI"/>
<owl:AnnotationProperty rdf:about="&oboInOwl;isCyclic"/>
<owl:AnnotationProperty rdf:about="&oboInOwl;inSubset"/>
<owl:AnnotationProperty rdf:about="&oboInOwl;savedBy"/>
<owl:AnnotationProperty rdf:about="&oboInOwl;replacedBy"/>
<owl:AnnotationProperty rdf:about="&oboInOwl;consider"/>
<owl:Class rdf:about="&oboInOwl;DbXref"/>
<owl:Class rdf:about="&oboInOwl;Definition"/>
<owl:Class rdf:about="&oboInOwl;Subset"/>
<owl:Class rdf:about="&oboInOwl;Synonym"/>
<owl:Class rdf:about="&oboInOwl;SynonymType"/>
<owl:Class rdf:about="&oboInOwl;ObsoleteClass"/>
<owl:ObjectProperty rdf:about="&oboInOwl;ObsoleteProperty"/>
<xsl:apply-templates select="obo/header"/>
<xsl:apply-templates select="obo/synonym_category"/>
<xsl:apply-templates select="obo/term[not(builtin) or builtin!='1']"/>
<xsl:apply-templates select="obo/typedef[not(builtin) or builtin!='1']"/>
<xsl:apply-templates select="obo/instance"/>
</rdf:RDF>
</xsl:template>
<!-- *********************************************** -->
<!-- GENERAL PURPOSE -->
<!-- *********************************************** -->
<!-- obo names correspond to rdfs labels -->
<xsl:template match="name">
<!-- all names are presumed to be in english -->
<rdfs:label xml:lang="en">
<xsl:value-of select="."/>
</rdfs:label>
</xsl:template>
<xsl:template mode="label" match="*|@*">
<!-- all names are presumed to be in english -->
<rdfs:label xml:lang="en">
<xsl:value-of select="."/>
</rdfs:label>
</xsl:template>
<!-- added 0.4 SA -->
<xsl:template match="description">
<rdfs:comment rdf:datatype="&xsd;string">
<xsl:value-of select="."/>
</rdfs:comment>
</xsl:template>
<!-- dbxrefs -->
<!-- in obo-xml, both dbxref and xref_analog refer to the same thing.
note that the tag now used in obo-text-1.2 is just 'xref' -->
<xsl:template match="dbxref|xref_analog|xref">
<oboInOwl:hasDbXref>
<oboInOwl:DbXref>
<rdfs:label>
<xsl:value-of select="dbname"/>
<xsl:text>:</xsl:text>
<xsl:value-of select="acc"/>
</rdfs:label>
<oboInOwl:hasURI rdf:datatype="&xsd;anyURI">
<xsl:choose>
<!-- typically OBO xrefs are in the form DB:ID - eg EC:1.1.1.1
on occasion the xref is also a URI. This this case it may be
mistakenly mis-parsed as DB=http, ID=//xxx.yyy.zzz/foo
we correct for that here -->
<xsl:when test="dbname='URL'">
<xsl:value-of select="acc"/>
</xsl:when>
<xsl:otherwise>
<xsl:text>&xref;</xsl:text>
<xsl:value-of select="dbname"/>
<xsl:text>#</xsl:text>
<xsl:value-of select="dbname"/>
<xsl:text>_</xsl:text>
<xsl:value-of select="acc"/>
</xsl:otherwise>
</xsl:choose>
</oboInOwl:hasURI>
</oboInOwl:DbXref>
</oboInOwl:hasDbXref>
</xsl:template>
<!-- *********************************************** -->
<!-- Synonmyms -->
<!-- *********************************************** -->
<xsl:template match="synonym[@scope='exact']">
<oboInOwl:hasExactSynonym>
<xsl:apply-templates mode="synonym" select="."/>
</oboInOwl:hasExactSynonym>
</xsl:template>
<xsl:template match="synonym[@scope='narrow']">
<oboInOwl:hasNarrowSynonym>
<xsl:apply-templates mode="synonym" select="."/>
</oboInOwl:hasNarrowSynonym>
</xsl:template>
<xsl:template match="synonym[@scope='broad']">
<oboInOwl:hasBroadSynonym>
<xsl:apply-templates mode="synonym" select="."/>
</oboInOwl:hasBroadSynonym>
</xsl:template>
<xsl:template match="synonym">
<oboInOwl:hasRelatedSynonym>
<xsl:apply-templates mode="synonym" select="."/>
</oboInOwl:hasRelatedSynonym>
</xsl:template>
<xsl:template mode="synonym" match="*">
<oboInOwl:Synonym>
<xsl:apply-templates mode="label" select="synonym_text"/>
<xsl:apply-templates select="dbxref"/>
</oboInOwl:Synonym>
</xsl:template>
<xsl:template match="synonym_category">
<oboInOwl:SynonymType>
<xsl:apply-templates select="id"/>
<xsl:apply-templates select="name"/>
<xsl:apply-templates select="namespace"/>
</oboInOwl:SynonymType>
</xsl:template>
<!-- *********************************************** -->
<!-- ONTOLOGY METADATA -->
<!-- *********************************************** -->
<!-- A subset is a view over an ontology -->
<xsl:template match="subsetdef">
<oboInOwl:hasSubset>
<oboInOwl:Subset>
<xsl:apply-templates select="id"/>
<rdfs:comment rdf:datatype="&xsd;string">
<xsl:value-of select="name"/>
</rdfs:comment>
<!-- subsetdefs can in theory have dbxrefs; no existing examples of this -->
<xsl:apply-templates select="dbxref"/>
</oboInOwl:Subset>
</oboInOwl:hasSubset>
</xsl:template>
<xsl:template match="idspace">
<oboInOwl:IDSpace>
<oboInOwl:local>
<xsl:value-of select="local"/>
</oboInOwl:local>
<oboInOwl:global>
<xsl:value-of select="global"/>
</oboInOwl:global>
<xsl:apply-templates select="comment"/>
</oboInOwl:IDSpace>
</xsl:template>
<xsl:template match="import">
<xsl:choose>
<xsl:when test="substring(.,string-length(.)-3) = '.obo'">
<owl:imports rdf:resource="{concat(substring(.,0,string-length(.)-3),'.owl')}"/>
</xsl:when>
<xsl:otherwise>
<owl:imports rdf:resource="{.}"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="format-version">
</xsl:template>
<xsl:template match="date">
<oboInOwl:hasDate>
<xsl:value-of select="."/>
</oboInOwl:hasDate>
</xsl:template>
<xsl:template match="saved-by">
<oboInOwl:savedBy>
<xsl:value-of select="."/>
</oboInOwl:savedBy>
</xsl:template>
<xsl:template match="auto-generated-by">
</xsl:template>
<xsl:template match="default-namespace">
<oboInOwl:hasDefaultNamespace>
<xsl:value-of select="."/>
</oboInOwl:hasDefaultNamespace>
</xsl:template>
<xsl:template match="remark">
<rdfs:comment>
<xsl:value-of select="."/>
</rdfs:comment>
</xsl:template>
<!-- *********************************************** -->
<!-- MAIN TEMPLATES -->
<!-- *********************************************** -->
<xsl:template match="header">
<!-- supply the Ontology metadata -->
<owl:Ontology rdf:about="">
<!-- most of these are not relevant in the OWL
transform but are required for round-tripping -->
<xsl:apply-templates select="import"/>
<xsl:apply-templates select="format-version"/>
<xsl:apply-templates select="date"/>
<xsl:apply-templates select="saved-by"/>
<xsl:apply-templates select="auto-generated-by"/>
<xsl:apply-templates select="default-namespace"/>
<xsl:apply-templates select="remark"/>
<!-- create an instance on OntologySubset for each subsetdef -->
<!-- OntologySubsets can be applied to multiple ontologies
- they are not specific to the ontology -->
<xsl:apply-templates select="subsetdef"/>
<rdfs:label>
<xsl:value-of select="default-namespace"/>
</rdfs:label>
<rdfs:comment>
<xsl:text>
This is an OWL translation of an ontology whose native representational form is .obo. The translation was performed using the oboInOwl xslt library. For details, see http://www.berkeleybop.org/obo-conv.cgi
</xsl:text>
</rdfs:comment>
</owl:Ontology>
</xsl:template>
<!-- *********************************************** -->
<!-- Terms/classes -->
<!-- *********************************************** -->
<xsl:template match="term">
<owl:Class>
<xsl:apply-templates select="id"/>
<xsl:apply-templates select="name"/>
<xsl:apply-templates select="comment"/>
<xsl:apply-templates select="subset"/>
<xsl:apply-templates select="def"/>
<xsl:apply-templates select="synonym"/>
<xsl:apply-templates select="consider|replaced_by"/>
<xsl:apply-templates select="namespace"/>
<xsl:apply-templates select="alt_id"/>
<xsl:apply-templates select="xref_analog|xref"/>
<xsl:apply-templates select="lexical_category"/>
<xsl:apply-templates select="is_a"/>
<xsl:apply-templates select="relationship"/>
<xsl:apply-templates select="property_value"/>
<xsl:apply-templates select="disjoint_from"/>
<!-- we treat obsoletes as subclasses of the obsolete class;
although they are not truly classes, we must treat them as
such to avoid falling into OWL full when we have documents
including out-of-date annotations to obsolete terms -->
<xsl:if test="is_obsolete='1'">
<rdfs:subClassOf rdf:resource="&oboInOwl;ObsoleteClass"/>
</xsl:if>
<!-- logical definitions -->
<xsl:if test="count(intersection_of)>0">
<owl:equivalentClass>
<owl:Class>
<owl:intersectionOf>
<xsl:attribute name="rdf:parseType">Collection</xsl:attribute>
<xsl:apply-templates select="intersection_of"/>
</owl:intersectionOf>
</owl:Class>
</owl:equivalentClass>
</xsl:if>
<xsl:if test="count(union_of)>0">
<owl:equivalentClass>
<owl:Class>
<owl:unionOf>
<xsl:attribute name="rdf:parseType">Collection</xsl:attribute>
<xsl:apply-templates select="union_of"/>
</owl:unionOf>
</owl:Class>
</owl:equivalentClass>
</xsl:if>
</owl:Class>
</xsl:template>
<xsl:template match="is_a">
<!-- by default we exclude inferred is_a relations -->
<!-- this is mostly used for obol output -->
<xsl:if test="not(@novel_inferred) and not(@problematic_inferred)">
<rdfs:subClassOf>
<xsl:apply-templates mode="resource" select="."/>
</rdfs:subClassOf>
</xsl:if>
<xsl:variable name="is_a">
<xsl:value-of select="."/>
</xsl:variable>
<xsl:variable name="this_id">
<xsl:value-of select="../id"/>
</xsl:variable>
<!-- experimental tag : so far implemented by CARO -->
<xsl:if test="/obo/header/pairwise-disjoint='true'">
<!--
this search is perhaps inefficient; we could use a key
here, but keys are prohibitively expensive on large ontologies
-->
<xsl:for-each select="//term[is_a=$is_a]/id">
<xsl:if test=".!=$this_id">
<owl:disjointWith>
<xsl:apply-templates mode="resource" select="."/>
</owl:disjointWith>
</xsl:if>
</xsl:for-each>
</xsl:if>
</xsl:template>
<xsl:template match="relationship">
<rdfs:subClassOf>
<xsl:apply-templates mode="restriction" select="."/>
</rdfs:subClassOf>
</xsl:template>
<!-- *** DL Constructs *** -->
<!-- currently we support intersection_of, union_of -->
<!-- TODO: disjoint_from, complement_of -->
<xsl:template match="intersection_of">
<xsl:choose>
<!-- genus -->
<!-- some species of obo use is_a(X) in intersection list -->
<xsl:when test="type='is_a' or not(type)">
<owl:Class>
<xsl:apply-templates mode="about" select="to"/>
</owl:Class>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates mode="restriction" select="."/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="union_of">
<owl:Class>
<xsl:apply-templates mode="about" select="."/>
</owl:Class>
</xsl:template>
<xsl:template match="disjoint_from">
<owl:disjointWith>
<xsl:apply-templates mode="resource" select="."/>
</owl:disjointWith>
</xsl:template>
<xsl:template mode="restriction" match="*">
<owl:Restriction>
<!-- only used if relationship is reified -->
<xsl:apply-templates select="@id"/>
<owl:onProperty>
<owl:ObjectProperty>
<xsl:apply-templates mode="about" select="type"/>
</owl:ObjectProperty>
</owl:onProperty>
<xsl:choose>
<xsl:when test="key('k_instance',to)">
<owl:hasValue>
<xsl:apply-templates mode="resource" select="to"/>
</owl:hasValue>
</xsl:when>
<xsl:otherwise>
<!-- TODO: For now we make the assumption that all relations
are existential (this is the case for all OBO relations)
may not be the case for non-foundry ontologies -->
<owl:someValuesFrom>
<xsl:apply-templates mode="resource" select="to"/>
</owl:someValuesFrom>
</xsl:otherwise>
</xsl:choose>
</owl:Restriction>
</xsl:template>
<xsl:template match="def">
<oboInOwl:hasDefinition>
<oboInOwl:Definition>
<xsl:apply-templates mode="label" select="defstr"/>
<xsl:apply-templates select="dbxref"/>
</oboInOwl:Definition>
</oboInOwl:hasDefinition>
</xsl:template>
<xsl:template match="comment">
<rdfs:comment rdf:datatype="&xsd;string">
<xsl:value-of select="."/>
</rdfs:comment>
</xsl:template>
<xsl:template match="namespace">
<xsl:if test=".!='unknown'">
<oboInOwl:hasOBONamespace>
<xsl:value-of select="."/>
</oboInOwl:hasOBONamespace>
</xsl:if>
</xsl:template>
<xsl:template match="alt_id">
<oboInOwl:hasAlternativeId>
<xsl:value-of select="."/>
</oboInOwl:hasAlternativeId>
</xsl:template>
<xsl:template match="lexical_category">
<oboInOwl:hasLexicalCategory>
<xsl:value-of select="."/>
</oboInOwl:hasLexicalCategory>
</xsl:template>
<xsl:template match="subset">
<oboInOwl:inSubset>
<xsl:apply-templates mode="resource" select="."/>
</oboInOwl:inSubset>
</xsl:template>
<xsl:template match="consider">
<oboInOwl:consider>
<xsl:apply-templates mode="resource" select="."/>
</oboInOwl:consider>
</xsl:template>
<xsl:template match="replaced_by">
<oboInOwl:replacedBy>
<xsl:apply-templates mode="resource" select="."/>
</oboInOwl:replacedBy>
</xsl:template>
<!-- *********************************************** -->
<!-- Relations -->
<!-- *********************************************** -->
<!-- In obo-xml, relations and datatype properties are confusingly
called "typedef" - the reasons for this are historical -->
<!-- These all map to owl properties -->
<!-- TODO:
Relation properties:
symmetric, anti_symmetric, reflexive
Transitive over (not yet supported in OWL 1.0 but supported in obo -->
<xsl:template match="typedef">
<xsl:choose>
<xsl:when test="is_transitive=1">
<xsl:element name="owl:TransitiveProperty">
<xsl:apply-templates mode="detail" select="."/>
</xsl:element>
</xsl:when>
<xsl:when test="is_metadata_tag=1">
<xsl:element name="owl:AnnotationProperty">
<xsl:apply-templates mode="detail" select="."/>
</xsl:element>
</xsl:when>
<xsl:when test="contains(range,'xsd:')">
<xsl:element name="owl:DatatypeProperty">
<xsl:apply-templates mode="detail" select="."/>
</xsl:element>
</xsl:when>
<xsl:otherwise>
<!-- TODO: datatype properties -->
<xsl:element name="owl:ObjectProperty">
<xsl:apply-templates mode="detail" select="."/>
</xsl:element>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template mode="detail" match="typedef">
<!-- most of the following are the same as for terms/classes -->
<xsl:apply-templates select="id"/>
<xsl:apply-templates select="name"/>
<xsl:apply-templates select="inverse_of"/>
<xsl:apply-templates select="domain"/>
<xsl:apply-templates select="range"/>
<xsl:apply-templates select="comment"/>
<xsl:apply-templates select="subset"/>
<xsl:apply-templates select="def"/>
<xsl:apply-templates select="synonym"/>
<xsl:apply-templates select="namespace"/>
<xsl:apply-templates select="alt_id"/>
<xsl:apply-templates select="xref_analog|xref"/>
<xsl:apply-templates select="lexical_category"/>
<xsl:if test="is_symmetric=1">
<rdf:type rdf:resource="&owl;SymmetricProperty"/>
</xsl:if>
<xsl:if test="is_functional=1">
<rdf:type rdf:resource="&owl;FunctionalProperty"/>
</xsl:if>
<xsl:if test="is_obsolete='1'">
<rdfs:subPropertyOf rdf:resource="&oboInOwl;ObsoleteProperty"/>
</xsl:if>
<!-- is_a is used for both subClassOf and subPropertyOf -->
<xsl:for-each select="is_a">
<rdfs:subPropertyOf>
<xsl:apply-templates mode="resource" select="."/>
</rdfs:subPropertyOf>
</xsl:for-each>
<xsl:apply-templates select="property_value"/>
</xsl:template>
<xsl:template match="inverse_of">
<owl:inverseOf>
<xsl:apply-templates mode="resource" select="."/>
</owl:inverseOf>
</xsl:template>
<xsl:template match="domain">
<rdfs:domain>
<xsl:apply-templates mode="resource" select="."/>
</rdfs:domain>
</xsl:template>
<xsl:template match="range">
<rdfs:range>
<xsl:apply-templates mode="resource" select="."/>
</rdfs:range>
</xsl:template>
<!-- *********************************************** -->
<!-- Instances -->
<!-- *********************************************** -->
<xsl:template match="instance">
<xsl:element name="rdf:Description">
<xsl:apply-templates select="id"/>
<xsl:apply-templates select="instance_of"/>
<xsl:apply-templates select="name"/>
<xsl:apply-templates select="namespace"/>
<xsl:apply-templates select="property_value"/>
</xsl:element>
</xsl:template>
<xsl:template match="instance_of">
<rdf:type>
<xsl:apply-templates mode="resource" select="."/>
</rdf:type>
</xsl:template>
<!-- TODO -->
<xsl:template match="property_value">
<xsl:variable name="property">
<xsl:choose>
<xsl:when test="contains(type,':')">
<xsl:value-of select="substring-after(type,':')"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="type"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:element name="{$property}">
<xsl:if test="contains(type,':')">
<xsl:attribute name="xmlns">
<xsl:variable name="ns">
<xsl:value-of select="substring-before(type,':')"/>
</xsl:variable>
<xsl:choose>
<xsl:when test="key('k_idspace',$ns)">
<xsl:value-of select="key('k_idspace',$ns)/global"/>
</xsl:when>
<xsl:otherwise>
<xsl:text>&oboContent;</xsl:text>
<xsl:value-of select="$ns"/>
<xsl:text>#</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
</xsl:if>
<xsl:choose>
<xsl:when test="datatype">
<xsl:attribute name="rdf:datatype">
<xsl:value-of select="datatype"/>
</xsl:attribute>
<xsl:value-of select="value"/>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates mode="resource" select="to"/>
</xsl:otherwise>
</xsl:choose>
</xsl:element>
</xsl:template>
<!-- *********************************************** -->
<!-- Annotations -->
<!-- *********************************************** -->
<!-- We treat obo annotations as reified links for now.
Future versions may use Named Graphs-->
<xsl:template match="annotation">
<oban:Annotation>
<oban:subject>
<xsl:apply-templates mode="resource" select="subject"/>
</oban:subject>
<oban:object>
<xsl:apply-templates mode="resource" select="subject"/>
</oban:object>
</oban:Annotation>
</xsl:template>
<!-- *********************************************** -->
<!-- Identifiers -->
<!-- *********************************************** -->
<!-- RDF stuff -->
<xsl:template match="id">
<xsl:attribute name="rdf:about">
<xsl:apply-templates mode="translate-id" select="."/>
</xsl:attribute>
</xsl:template>
<xsl:template match="@id">
<xsl:attribute name="rdf:about">
<xsl:apply-templates mode="translate-id" select="."/>
</xsl:attribute>
</xsl:template>
<xsl:template mode="resource" match="*">
<xsl:attribute name="rdf:resource">
<xsl:apply-templates mode="translate-id" select="."/>
</xsl:attribute>
</xsl:template>
<xsl:template mode="about" match="*">
<xsl:attribute name="rdf:about">
<xsl:apply-templates mode="translate-id" select="."/>
</xsl:attribute>
</xsl:template>
<xsl:template mode="translate-id" match="@*|*">
<!-- split the bipartite OBO ID in two -
-->
<xsl:variable name="idspace">
<xsl:value-of select="substring-before(.,':')"/>
</xsl:variable>
<xsl:variable name="localid">
<xsl:value-of select="substring-after(.,':')"/>
</xsl:variable>
<!-- handle the ID based on its content -->
<xsl:choose>
<!-- anonymous classes -
denoted by an IDSpace of a single underscore -->
<xsl:when test="$idspace = '_'">
<xsl:value-of select="$localid"/>
</xsl:when>
<!-- builtin -->
<xsl:when test="$idspace = 'xsd'">
<xsl:text>&xsd;</xsl:text>
<xsl:value-of select="$localid"/>
</xsl:when>
<!-- is the idspace mapped in the header of the file? -->
<xsl:when test="key('k_idspace',substring-before(.,':'))">
<xsl:value-of select="key('k_idspace',substring-before(.,':'))/global"/>
<xsl:if test="$localid_prefix">
<xsl:value-of select="$localid_prefix"/>
</xsl:if>
<xsl:value-of select="substring-after(.,':')"/>
</xsl:when>
<!-- idspace is specified, but not mapped in the header -->
<xsl:when test="substring-before(.,':')">
<xsl:text>&oboContent;</xsl:text>
<xsl:value-of select="$idspace"/>
<xsl:text>#</xsl:text>
<xsl:if test="number(substring($localid,1,1)) or substring($localid,1,1)='0'">
<xsl:value-of select="$idspace"/>
<xsl:text>_</xsl:text>
</xsl:if>
<xsl:if test="$localid_prefix">
<xsl:value-of select="$localid_prefix"/>
</xsl:if>
<xsl:value-of select="substring-after(.,':')"/>
</xsl:when>
<!-- no idspace: ID is flat (eg part_of) -->
<!-- first we check if this ID is for a relation, and that relation is in OBO_REL -->
<xsl:when test="key('k_relation',.)/xref_analog/dbname = 'OBO_REL'">
<xsl:variable name="new-id">
<xsl:value-of select="key('k_relation',.)/xref_analog[dbname='OBO_REL']/acc"/>
</xsl:variable>
<xsl:choose>
<!-- is the idspace mapped? -->
<xsl:when test="key('k_idspace','OBO_REL')">
<xsl:value-of select="key('k_idspace',substring-before(.,':'))/global"/>
<xsl:value-of select="$new-id"/>
</xsl:when>
<xsl:otherwise>
<xsl:text>&oboContent;</xsl:text>
<xsl:text>OBO_REL#</xsl:text>
<xsl:value-of select="$new-id"/>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<!-- flat ID, not in OBO_REL -->
<xsl:otherwise>
<xsl:text>&oboContent;</xsl:text>
<xsl:choose>
<xsl:when test="$localid_prefix">
<xsl:value-of select="$localid_prefix"/>
</xsl:when>
<xsl:otherwise>
<xsl:text>obo#</xsl:text>
</xsl:otherwise>
</xsl:choose>
<xsl:value-of select="."/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- *********************************************** -->
</xsl:stylesheet>
|