Example #1
0
    def to_tccm_rdf(self, see_also_format=''):
        cs_uri = URIRef("http://ncicb.nci.nih.gov/xml/owl/EVS/Thesaurus.owl")
        self.graph.add((cs_uri, RDF.type, SKOS.ConceptScheme))
        self.graph.add((
            cs_uri, DC.description,
            Literal(
                "A vocabulary for clinical care, translational and basic research, and public information and administrative activities."
            )))
        self.graph.add(
            (cs_uri, RDFS.seeAlso,
             Literal("https://ncithesaurus.nci.nih.gov/ncitbrowser/")))
        self.graph.add(
            (cs_uri, SH.namespace,
             URIRef("http://ncicb.nci.nih.gov/xml/owl/EVS/Thesaurus.owl#")))

        for line in self.zipfile.open("Thesaurus.txt"):
            tokens = line.decode("utf-8").split("\t")
            uri = URIRef(tokens[1][1:-1])
            self.graph.add((uri, RDF.type, SKOS.Concept))
            self.graph.add((uri, SKOS.notation, Literal(tokens[0])))
            self.graph.add((uri, SKOS.definition, Literal(tokens[4])))
            self.graph.add(
                (uri, SKOS.prefLabel, Literal(tokens[3].split("|")[0])))
            if tokens[2]:
                for code in tokens[2].split("|"):
                    code = code.strip()
                    sc_uri = URIRef(curie_to_uri(f"NCIT:{code}", NAMESPACES))
                    self.graph.add((uri, SKOS.broader, sc_uri))
            see_also = f"https://ncit.nci.nih.gov/ncitbrowser/pages/concept_details.jsf?dictionary=NCI%20Thesaurus&code={tokens[0]}"
            self.graph.add((uri, RDFS.seeAlso, Literal(see_also)))
            self.graph.add((uri, SKOS.inScheme, cs_uri))
        with open('ncit-termci.ttl', 'w') as file:
            file.write(self.graph.serialize(format='turtle').decode('utf-8'))
def get_concept_reference_by_id(curie: str, request: Request,
                                response: Response):
    graph: TccmGraph = request.app.state.graph
    new_value = unquote(curie_to_uri(curie))
    records = graph.get_concept_references_by_value(
        ConceptReferenceKeyName.curie, new_value, SearchModifier.equals)
    if not records:
        raise HTTPException(
            status_code=404,
            detail=f"ConceptReference curie={curie} not found.")
    response.headers['Link'] = build_jsonld_link_header(
        str(request.base_url) + request.scope.get("root_path"),
        'termci_schema')
    return records[0]
def get_concept_references(key: ConceptReferenceKeyName, value: str,
                           modifier: SearchModifier, request: Request,
                           response: Response):
    graph: TccmGraph = request.app.state.graph
    new_value = value
    if key == ConceptReferenceKeyName.uri:
        new_value = unquote(value)
    elif key == ConceptReferenceKeyName.curie:
        new_value = unquote(curie_to_uri(value))
    records = graph.get_concept_references_by_value(key, new_value, modifier)
    if not records:
        raise HTTPException(
            status_code=404,
            detail=f"ConceptReference {key}={value}|{modifier} not found.")
    response.headers['Link'] = build_jsonld_link_header(
        str(request.base_url) + request.scope.get("root_path"),
        'termci_schema')
    return records
Example #4
0
def test_curie_to_uri_ncit():
    curie = "NCIT:C7227"
    uri = curie_to_uri(curie, NAMESPACES)
    assert uri == "http://purl.obolibrary.org/obo/NCIT_C7227"
Example #5
0
def test_curie_to_uri_uri():
    curie = "https://ontologies-r.us/ontology/ICD-O-3-M/800"
    uri = curie_to_uri(curie, NAMESPACES)
    assert uri == "https://ontologies-r.us/ontology/ICD-O-3-M/800"