Форматирование RDF-файла Web Ontology в ОС Centos - PullRequest
0 голосов
/ 13 июля 2020

Я пытаюсь переформатировать файл RDF для LOIN C. Файл выглядит примерно так:

   <!-- 
        ///////////////////////////////////////////////////////////////////////////////////////
        //
        // Classes
        //
        ///////////////////////////////////////////////////////////////////////////////////////
         -->
    .
    .
    .   
    
    
      <!-- https://loinc.org/LP189614-3 -->

    <owl:Class rdf:about="https://loinc.org/LP189614-3">
        <rdfs:subClassOf rdf:resource="https://loinc.org/LP173103-5"/>
        <rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Weight management summary (LP)</rdfs:label>
        <skos:prefLabel rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Weight management summary</skos:prefLabel>
        <loinc:hasCode rdf:datatype="http://www.w3.org/2001/XMLSchema#string">LP189614-3</loinc:hasCode>
    </owl:Class>
    
  .
  .
  .
  .

<!-- https://loinc.org/LP173103-5 -->

    <owl:Class rdf:about="https://loinc.org/LP173103-5">
        <rdfs:subClassOf rdf:resource="https://loinc.org/LP173122-5"/>
        <rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Summary (LP)</rdfs:label>
        <skos:prefLabel rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Summary</skos:prefLabel>
        <loinc:hasCode rdf:datatype="http://www.w3.org/2001/XMLSchema#string">LP173103-5</loinc:hasCode>
    </owl:Class>
    
.
.

.
    <!-- https://loinc.org/LP192135-4 -->

    <owl:Class rdf:about="https://loinc.org/LP192135-4">
        <rdfs:subClassOf rdf:resource="https://loinc.org/LP172961-7"/>
        <rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Birth defects (LP)</rdfs:label>
        <skos:prefLabel rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Birth defects</skos:prefLabel>
        <loinc:hasCode rdf:datatype="http://www.w3.org/2001/XMLSchema#string">LP192135-4</loinc:hasCode>
    </owl:Class>   
    .
    .
    .

Весь файл имеет размер 5 МБ и доступен Здесь . Вывод файла должен быть JSON, и для каждого класса совы результат должен выглядеть следующим образом.

{
  "id": "https://loinc.org/LP189614-3",#The subject URI without enclosing <> 
  "Label":"Weight management summary", #The text label of a Concept: <skos:prefLabel rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Weight management summary</skos:prefLabel>**
  "Definition": "", #The text definition of a Concept. Empty since there is no definition
  "Alt_Definition":"", #Alternate Definition(s) of a Concept. Empty since there is no alt_definition
  "Synonyms":"Weight management summary", #Synonym(s) for a Concept: <rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Weight management summary (LP)</rdfs:label>
  "Parent":"Summary", #Superclass(es): Get Parents <skos:prefLabel rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Summary</skos:prefLabel>**
  "Child":"", #Subclass(es): PrefLabels of all subClasses
  "ICD_and_skosNotation":"", #ICD9 or ICD10 codes. Empty since there is none
  "Genes":"", #Associated Genes
  "Source_Ontology":"LOINC", #Ontology a Concept is derived from: Always LOINC
  "Data_Element_Mapping":0, #Flag indicating if the Concept has a Mapped Data Element
  "Data_Element":0, #Flag indicating if the Concept is a Data Element
  "General":"", #Field to accommodate any data not captured elsewhere in the schema
}

У меня есть базовые c знания Sed и Awk, но это кажется более сложным, чем это потому, что для каждого класса совы необходимы все его родители и дети. Существуют ли какие-либо инструменты или сценарии, которые могут упростить это форматирование?

Согласно предложению, я использовал следующее, чтобы преобразовать RDF в JSON. Однако я не знаю, как получить информацию о родителях и детях.

from rdflib import plugin, Graph
from rdflib.serializer import Serializer

g=Graph()
g.parse(location='LOINC.rdf',format='application/rdf+xml')
g.serialize(destination='output_json-ld.txt',format='json-ld',indent=4)
...