Skip to content

Commit

Permalink
Merge pull request #238 from linkml/rdflib-percent-encoded-tests
Browse files Browse the repository at this point in the history
Rdflib percent encoded tests
  • Loading branch information
cmungall authored Jan 18, 2023
2 parents 32cd5f0 + fcbd2cb commit 1aae031
Show file tree
Hide file tree
Showing 22 changed files with 7,493 additions and 7 deletions.
4 changes: 2 additions & 2 deletions linkml_runtime/dumpers/rdflib_dumper.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ def dumps(self, element: YAMLRoot, schemaview: SchemaView = None,
return self.as_rdf_graph(element, schemaview, prefix_map=prefix_map).\
serialize(format=fmt)

def _as_uri(self, element_id: str, id_slot: SlotDefinition, schemaview: SchemaView) -> URIRef:
if schemaview.is_slot_percent_encoded(id_slot):
def _as_uri(self, element_id: str, id_slot: Optional[SlotDefinition], schemaview: SchemaView) -> URIRef:
if id_slot and schemaview.is_slot_percent_encoded(id_slot):
return URIRef(urllib.parse.quote(element_id))
else:
return schemaview.namespaces().uri_for(element_id)
Expand Down
37 changes: 37 additions & 0 deletions tests/test_loaders_dumpers/input/phenopackets/any.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@

classes:
Any:
attributes:
typeUrl:
annotations:
rank: 1
description: "A URL/resource name that uniquely identifies the type of the serialized protocol buffer message. This string must contain at least one \"/\" character. The last segment of the URL's path must represent the fully qualified name of the type (as in `path/google.protobuf.Duration`). The name should be in a canonical form (e.g., leading \".\" is not accepted). In practice, teams usually precompile into the binary all types that they expect it to use in the context of Any. However, for URLs which use the scheme `http`, `https`, or no scheme, one can optionally set up a type server that maps type URLs to message definitions as follows: * If no scheme is provided, `https` is assumed. * An HTTP GET on the URL must yield a [google.protobuf.Type][] value in binary format, or produce an error. * Applications are allowed to cache lookup results based on the URL, or have them precompiled into a binary to avoid any lookup. Therefore, binary compatibility needs to be preserved on changes to types. (Use versioned type names to manage breaking changes.) Note: this functionality is not currently available in the official protobuf release, and it is not used for type URLs beginning with type.googleapis.com. Schemes other than `http`, `https` (or the empty scheme) might be used with implementation specific semantics. "
range: string
value:
annotations:
rank: 2
description: Must be a valid serialized protocol buffer of the above specified type.
range: string
description: "`Any` contains an arbitrary serialized protocol buffer message along with a URL that describes the type of the serialized message. Protobuf library provides support to pack/unpack Any values in the form of utility functions or additional generated methods of the Any type. Example 1: Pack and unpack a message in C++. Foo foo = ...; Any any; any.PackFrom(foo); ... if (any.UnpackTo(&foo)) { ... } Example 2: Pack and unpack a message in Java. Foo foo = ...; Any any = Any.pack(foo); ... if (any.is(Foo.class)) { foo = any.unpack(Foo.class); } Example 3: Pack and unpack a message in Python. foo = Foo(...) any = Any() any.Pack(foo) ... if any.Is(Foo.DESCRIPTOR): any.Unpack(foo) ... Example 4: Pack and unpack a message in Go foo := &pb.Foo{...} any, err := anypb.New(foo) if err != nil { ... } ... foo := &pb.Foo{} if err := any.UnmarshalTo(foo); err != nil { ... } The pack methods provided by protobuf library will by default use 'type.googleapis.com/full.type.name' as the type URL and the unpack methods only use the fully qualified type name after the last '/' in the type URL, for example \"foo.bar.com/x/y.z\" will yield type name \"y.z\". JSON ==== The JSON representation of an `Any` value uses the regular representation of the deserialized, embedded message, with an additional field `@type` which contains the type URL. Example: package google.profile; message Person { string first_name = 1; string last_name = 2; } { \"@type\": \"type.googleapis.com/google.profile.Person\", \"firstName\": <string>, \"lastName\": <string> } If the embedded message type is well-known and has a custom JSON representation, that representation will be embedded adding a field `value` which holds the custom JSON in addition to the `@type` field. Example (for message [google.protobuf.Duration][]): { \"@type\": \"type.googleapis.com/google.protobuf.Duration\", \"value\": \"1.212s\" } "
default_prefix: any
description: "Automatic translation of phenopackets protobuf to LinkML. Status: EXPERIMENTAL."
enums: {}

id: https://w3id.org/linkml/phenopackets/any
imports:
- linkml:types
name: any
prefixes:
GENO: http://purl.obolibrary.org/obo/GENO_
HP: http://purl.obolibrary.org/obo/HP_
LOINC: https://loinc.org/
MONDO: http://purl.obolibrary.org/obo/MONDO_
NCIT: http://purl.obolibrary.org/obo/NCIT_
UBERON: http://purl.obolibrary.org/obo/UBERON_
UCUM: http://unitsofmeasure.org/
UO: http://purl.obolibrary.org/obo/UO_
any: https://w3id.org/linkml/phenopackets/any/
argo: https://docs.icgc-argo.org/dictionary/
linkml: https://w3id.org/linkml/
slots: {}

228 changes: 228 additions & 0 deletions tests/test_loaders_dumpers/input/phenopackets/base.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,228 @@

classes:
Age:
attributes:
iso8601duration:
annotations:
rank: 1
description: The :ref:`ISO 8601<metadata_date_time>` age of this object as ISO8601 duration or time intervals. e.g. P40Y10M05D)
range: string
description: See http://build.fhir.org/datatypes and http://build.fhir.org/condition-definitions.html#Condition.onset_x_ In FHIR this is represented as a UCUM measurement - http://unitsofmeasure.org/trac/
AgeRange:
attributes:
end:
annotations:
rank: 2
description: ''
range: Age
start:
annotations:
rank: 1
description: ''
range: Age
description: ''
Dictionary:
comments:
- TODO
Evidence:
attributes:
evidenceCode:
annotations:
rank: 1
description: "The encoded evidence type using, for example the Evidence & Conclusion Ontology (ECO - http://purl.obolibrary.org/obo/eco.owl) FHIR mapping: Condition.evidence.code"
inlined: true
range: OntologyClass
reference:
annotations:
rank: 2
description: "FHIR mapping: Condition.evidence.detail"
inlined: true
range: ExternalReference
description: "FHIR mapping: Condition.evidence (https://www.hl7.org/fhir/condition-definitions.html#Condition.evidence)"
ExternalReference:
attributes:
description:
annotations:
rank: 3
description: "Human readable title or display string for the reference FHIR mapping: Reference.display"
range: string
id:
annotations:
percent_encoded: true
rank: 1
description: "e.g. ISBN, PMID:123456, DOI:..., FHIR mapping: Reference.identifier"
range: string
reference:
annotations:
rank: 2
description: A full or partial URL pointing to the external reference if no commonly resolvable identifier can be used in the `id` field FHIR mapping Reference.reference
range: string
description: "FHIR mapping: Reference (https://www.hl7.org/fhir/references.html)"
File:
attributes:
fileAttributes:
annotations:
rank: 3
description: Map of attributes describing the file. For example the File format or genome assembly would be defied here. For genomic data files there MUST be a 'genomeAssembly' key.
inlined: true
range: Dictionary
individualToFileIdentifiers:
annotations:
rank: 2
description: A map of identifiers mapping an individual to a sample in the file. The key values must correspond to the Individual::id for the individuals in the message, the values must map to the samples in the file.
inlined: true
range: Dictionary
uri:
annotations:
rank: 1
description: URI for the file e.g. file://data/genomes/file1.vcf.gz or https://opensnp.org/data/60.23andme-exome-vcf.231?1341012444
range: string
description: ''
GestationalAge:
attributes:
days:
annotations:
rank: 2
description: ''
range: integer
weeks:
annotations:
rank: 1
description: ''
range: integer
description: ''
OntologyClass:
attributes:
id:
annotations:
rank: 1
description: a CURIE-style identifier e.g. HP:0100024, MP:0001284, UBERON:0001690. This is the primary key for the ontology class REQUIRED!
identifier: true
range: string
required: true
label:
annotations:
rank: 2
description: class label, aka name. E.g. "Abnormality of cardiovascular system"
range: string
description: "A class (aka term, concept) in an ontology. FHIR mapping: CodeableConcept (http://www.hl7.org/fhir/datatypes.html#CodeableConcept) see also Coding (http://www.hl7.org/fhir/datatypes.html#Coding)"
Procedure:
attributes:
bodySite:
annotations:
rank: 2
description: "FHIR mapping: Procedure.bodySite"
inlined: true
range: OntologyClass
code:
annotations:
rank: 1
description: "FHIR mapping: Procedure.code"
inlined: true
range: OntologyClass
performed:
annotations:
rank: 3
description: When the procedure was performed.
inlined: true
range: TimeElement
description: "A clinical procedure performed on a subject. By preference a single concept to indicate both the procedure and the body site should be used. In cases where this is not possible, the body site should be indicated using a separate ontology class. e.g. {\"code\":{\"NCIT:C51585\": \"Biopsy of Soft Palate\"}} {\"code\":{\"NCIT:C28743\": \"Punch Biopsy\"}, \"body_site\":{\"UBERON:0003403\": \"skin of forearm\"}} - a punch biopsy of the skin from the forearm FHIR mapping: Procedure (https://www.hl7.org/fhir/procedure.html)"
TimeElement:
attributes:
age:
annotations:
rank: 1
description: ''
range: Age
ageRange:
annotations:
rank: 2
description: ''
range: AgeRange
gestationalAge:
annotations:
rank: 6
description: ''
range: GestationalAge
interval:
annotations:
rank: 5
description: ''
inlined: true
range: TimeInterval
ontologyClass:
annotations:
rank: 3
description: ''
inlined: true
range: OntologyClass
timestamp:
annotations:
rank: 4
description: ''
range: string
description: ''
rules:
-
postconditions:
exactly_one_of:
-
slot_conditions:
gestationalAge:
required: true
-
slot_conditions:
age:
required: true
-
slot_conditions:
ageRange:
required: true
-
slot_conditions:
ontologyClass:
required: true
-
slot_conditions:
timestamp:
required: true
-
slot_conditions:
interval:
required: true
TimeInterval:
attributes:
end:
annotations:
rank: 2
description: ''
range: string
start:
annotations:
rank: 1
description: ''
range: string
description: ''
default_prefix: base
description: "Automatic translation of phenopackets protobuf to LinkML. Status: EXPERIMENTAL."
enums: {}

id: https://w3id.org/linkml/phenopackets/base
imports:
- linkml:types
- timestamp
name: base
prefixes:
GENO: http://purl.obolibrary.org/obo/GENO_
HP: http://purl.obolibrary.org/obo/HP_
LOINC: https://loinc.org/
MONDO: http://purl.obolibrary.org/obo/MONDO_
NCIT: http://purl.obolibrary.org/obo/NCIT_
UBERON: http://purl.obolibrary.org/obo/UBERON_
UCUM: http://unitsofmeasure.org/
UO: http://purl.obolibrary.org/obo/UO_
argo: https://docs.icgc-argo.org/dictionary/
base: https://w3id.org/linkml/phenopackets/base/
linkml: https://w3id.org/linkml/
slots: {}

Loading

0 comments on commit 1aae031

Please sign in to comment.