-
Notifications
You must be signed in to change notification settings - Fork 1
Addition of solid classes Email and Telephone #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
hkir-dev
wants to merge
6
commits into
main
Choose a base branch
from
email_object
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+278
−10
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2185748
email and telephone objects added
hkir-dev 91540be
rollback rdfjs-wrapper version upgrade
hkir-dev 91e63a4
typo fix
hkir-dev e9f4473
unit tests added
hkir-dev 9cae83d
equivalent properties handled
hkir-dev fa2769e
Telephone getter default value removed
hkir-dev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import { TermWrapper, ValueMappings, TermMappings } from 'rdfjs-wrapper'; | ||
| import { VCARD, RDF } from '../vocabulary/mod.js'; | ||
|
|
||
| export class Email extends TermWrapper { | ||
| get emailAddress(): string { | ||
| return this.singular(VCARD.value, ValueMappings.literalToString); | ||
| } | ||
|
|
||
| set emailAddress(value: string) { | ||
| this.overwrite(VCARD.value, value, TermMappings.stringToLiteral); | ||
| } | ||
|
|
||
| get emailType(): string | undefined { | ||
| return this.singularNullable(RDF.type, ValueMappings.iriToString); | ||
| } | ||
|
|
||
| set emailType(value: string | undefined) { | ||
| this.overwriteNullable(RDF.type, value, TermMappings.stringToIri); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| import { DatasetWrapper } from 'rdfjs-wrapper'; | ||
| import { VCARD } from '../vocabulary/mod.js'; | ||
| import { Email } from './Email.js'; | ||
|
|
||
| export class EmailDataset extends DatasetWrapper { | ||
| get emails(): Iterable<Email> { | ||
| const objects = new Set([ | ||
| ...this.instancesOf(VCARD.Email, Email), | ||
| ...this.objectsOf(VCARD.hasEmail, Email), | ||
| ...this.objectsOf(VCARD.email, Email), | ||
| ]) | ||
|
|
||
| return objects | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import { TermWrapper, ValueMappings, TermMappings } from 'rdfjs-wrapper'; | ||
| import { VCARD } from '../vocabulary/mod.js'; | ||
|
|
||
| export class Telephone extends TermWrapper { | ||
| get phoneNumber(): string { | ||
| return this.singular(VCARD.hasValue, ValueMappings.literalToString); | ||
| } | ||
langsamu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| set phoneNumber(value: string) { | ||
| this.overwrite(VCARD.hasValue, value, TermMappings.stringToLiteral); | ||
| } | ||
|
|
||
| get phoneType(): string | undefined { | ||
| return this.singularNullable(VCARD.telephoneType, ValueMappings.iriToString); | ||
| } | ||
|
|
||
| set phoneType(value: string | undefined) { | ||
| this.overwriteNullable(VCARD.telephoneType, value, TermMappings.stringToIri); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| import { DatasetWrapper } from 'rdfjs-wrapper'; | ||
| import { VCARD } from '../vocabulary/vcard.js'; | ||
| import { Telephone } from './Telephone.js'; | ||
|
|
||
| export class TelephoneDataset extends DatasetWrapper { | ||
| get telephones(): Iterable<Telephone> { | ||
| const objects = new Set([ | ||
| ...this.objectsOf(VCARD.hasTelephone, Telephone), | ||
| ...this.objectsOf(VCARD.tel, Telephone), | ||
| ]) | ||
|
|
||
| return objects | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,7 @@ | ||
| export * from "./Container.js" | ||
| export * from "./ContainerDataset.js" | ||
| export * from "./Resource.js" | ||
| export * from "./Email.js"; | ||
| export * from "./EmailDataset.js"; | ||
| export * from "./Telephone.js"; | ||
| export * from "./TelephoneDataset.js"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,17 @@ | ||
|
|
||
| export const VCARD = { | ||
| fn: "http://www.w3.org/2006/vcard/ns#fn", | ||
| hasEmail: "http://www.w3.org/2006/vcard/ns#hasEmail", | ||
| hasValue: "http://www.w3.org/2006/vcard/ns#hasValue", | ||
| hasPhoto: "http://www.w3.org/2006/vcard/ns#hasPhoto", | ||
| hasTelephone: "http://www.w3.org/2006/vcard/ns#hasTelephone", | ||
| title: "http://www.w3.org/2006/vcard/ns#title", | ||
| hasUrl: "http://www.w3.org/2006/vcard/ns#hasUrl", | ||
| organizationName: "http://www.w3.org/2006/vcard/ns#organization-name", | ||
| role: "http://www.w3.org/2006/vcard/ns#organization-name", | ||
| fn: "http://www.w3.org/2006/vcard/ns#fn", | ||
| Email: "http://www.w3.org/2006/vcard/ns#Email", | ||
| email: "http://www.w3.org/2006/vcard/ns#email", | ||
| hasEmail: "http://www.w3.org/2006/vcard/ns#hasEmail", | ||
| hasValue: "http://www.w3.org/2006/vcard/ns#hasValue", | ||
| hasPhoto: "http://www.w3.org/2006/vcard/ns#hasPhoto", | ||
| tel: "http://www.w3.org/2006/vcard/ns#tel", | ||
| hasTelephone: "http://www.w3.org/2006/vcard/ns#hasTelephone", | ||
| title: "http://www.w3.org/2006/vcard/ns#title", | ||
| hasUrl: "http://www.w3.org/2006/vcard/ns#hasUrl", | ||
| organizationName: "http://www.w3.org/2006/vcard/ns#organization-name", | ||
| phone: "http://www.w3.org/2006/vcard/ns#phone", | ||
| role: "http://www.w3.org/2006/vcard/ns#role", | ||
| value: "http://www.w3.org/2006/vcard/ns#value", | ||
| telephoneType: "http://www.w3.org/2006/vcard/ns#TelephoneType", | ||
| } as const; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| import { DataFactory, Parser, Store } from "n3" | ||
| import assert from "node:assert" | ||
| import { describe, it } from "node:test" | ||
|
|
||
| import { Email } from "@solid/object"; | ||
|
|
||
| describe("Email tests", () => { | ||
|
|
||
| const sampleRDF = ` | ||
| @prefix vcard: <http://www.w3.org/2006/vcard/ns#> . | ||
| @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . | ||
|
|
||
| <https://example.org/person/1> | ||
| a vcard:Individual ; | ||
| vcard:fn "Alice" ; | ||
| vcard:hasEmail <https://example.org/email/1> . | ||
|
|
||
| <https://example.org/email/1> | ||
| a vcard:Email ; | ||
| vcard:value "alice@example.org" ; | ||
| rdf:type vcard:Work . | ||
| `; | ||
|
|
||
| it("should parse and retrieve email address", () => { | ||
| const store = new Store() | ||
| store.addQuads(new Parser().parse(sampleRDF)) | ||
|
|
||
| const email = new Email( | ||
| DataFactory.namedNode("https://example.org/email/1"), | ||
| store, | ||
| DataFactory | ||
| ) | ||
|
|
||
| assert.equal(email.emailAddress, "alice@example.org") | ||
| assert.equal(typeof email.emailAddress, "string") | ||
| }) | ||
|
|
||
| it("should allow setting email address", () => { | ||
| const store = new Store() | ||
| store.addQuads(new Parser().parse(sampleRDF)) | ||
|
|
||
| const email = new Email( | ||
| DataFactory.namedNode("https://example.org/email/1"), | ||
| store, | ||
| DataFactory | ||
| ) | ||
|
|
||
| email.emailAddress = "bob@example.org" | ||
|
|
||
| assert.equal(email.emailAddress, "bob@example.org") | ||
| }) | ||
|
|
||
| it("should parse and retrieve email type", () => { | ||
| const store = new Store() | ||
| store.addQuads(new Parser().parse(sampleRDF)) | ||
|
|
||
| const email = new Email( | ||
| DataFactory.namedNode("https://example.org/email/1"), | ||
| store, | ||
| DataFactory | ||
| ) | ||
|
|
||
| const emailType = DataFactory.namedNode("http://www.w3.org/2006/vcard/ns#Home") | ||
|
|
||
| assert.ok(emailType !== undefined) | ||
| assert.equal(typeof emailType, "object") | ||
| assert.equal(emailType.value, "http://www.w3.org/2006/vcard/ns#Home") | ||
| }) | ||
|
|
||
| it("should allow setting email type", () => { | ||
| const store = new Store() | ||
|
|
||
| const email = new Email( | ||
| DataFactory.namedNode("https://example.org/email/2"), | ||
| store, | ||
| DataFactory | ||
| ) | ||
|
|
||
| email.emailAddress = "test@example.org" | ||
| email.emailType = "http://www.w3.org/2006/vcard/ns#Home" | ||
|
|
||
| assert.equal(email.emailType, "http://www.w3.org/2006/vcard/ns#Home") | ||
| }) | ||
|
|
||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| import { DataFactory, Parser, Store } from "n3" | ||
| import assert from "node:assert" | ||
| import { describe, it } from "node:test" | ||
|
|
||
| import { Telephone } from "@solid/object"; | ||
|
|
||
| describe("Telephone tests", () => { | ||
|
|
||
| const sampleRDF = ` | ||
| @prefix vcard: <http://www.w3.org/2006/vcard/ns#> . | ||
|
|
||
| <https://example.org/person/1> | ||
| a vcard:Individual ; | ||
| vcard:fn "Alice" ; | ||
| vcard:hasTelephone <https://example.org/phone/1> . | ||
|
|
||
| <https://example.org/phone/1> | ||
| a vcard:Telephone ; | ||
| vcard:hasValue "+1234567890" ; | ||
| vcard:TelephoneType vcard:Cell . | ||
| `; | ||
|
|
||
| it("should parse and retrieve phone number", () => { | ||
| const store = new Store() | ||
| store.addQuads(new Parser().parse(sampleRDF)) | ||
|
|
||
| const telephone = new Telephone( | ||
| DataFactory.namedNode("https://example.org/phone/1"), | ||
| store, | ||
| DataFactory | ||
| ) | ||
|
|
||
| assert.equal(telephone.phoneNumber, "+1234567890") | ||
| assert.equal(typeof telephone.phoneNumber, "string") | ||
| }) | ||
|
|
||
| it("should allow setting phone number", () => { | ||
| const store = new Store() | ||
| store.addQuads(new Parser().parse(sampleRDF)) | ||
|
|
||
| const telephone = new Telephone( | ||
| DataFactory.namedNode("https://example.org/phone/1"), | ||
| store, | ||
| DataFactory | ||
| ) | ||
|
|
||
| telephone.phoneNumber = "+0987654321" | ||
|
|
||
| assert.equal(telephone.phoneNumber, "+0987654321") | ||
| }) | ||
|
|
||
| it("should parse and retrieve phone type", () => { | ||
| const store = new Store() | ||
| store.addQuads(new Parser().parse(sampleRDF)) | ||
|
|
||
| const telephone = new Telephone( | ||
| DataFactory.namedNode("https://example.org/phone/1"), | ||
| store, | ||
| DataFactory | ||
| ) | ||
|
|
||
| const phoneType = telephone.phoneType | ||
|
|
||
| assert.ok(phoneType !== undefined) | ||
| assert.equal(typeof phoneType, "string") | ||
| assert.equal(phoneType, "http://www.w3.org/2006/vcard/ns#Cell") | ||
| }) | ||
|
|
||
| it("should allow setting phone type", () => { | ||
| const store = new Store() | ||
|
|
||
| const telephone = new Telephone( | ||
| DataFactory.namedNode("https://example.org/phone/2"), | ||
| store, | ||
| DataFactory | ||
| ) | ||
|
|
||
| telephone.phoneNumber = "+1112223333" | ||
| telephone.phoneType = "http://www.w3.org/2006/vcard/ns#Car" | ||
|
|
||
| assert.equal(telephone.phoneType, "http://www.w3.org/2006/vcard/ns#Car") | ||
| }) | ||
|
|
||
| it("should throw when phone number is missing", () => { | ||
| const noPhoneRDF = ` | ||
| @prefix vcard: <http://www.w3.org/2006/vcard/ns#> . | ||
|
|
||
| <https://example.org/phone/empty> | ||
| a vcard:Telephone . | ||
| ` | ||
| const store = new Store() | ||
| store.addQuads(new Parser().parse(noPhoneRDF)) | ||
|
|
||
| const telephone = new Telephone( | ||
| DataFactory.namedNode("https://example.org/phone/empty"), | ||
| store, | ||
| DataFactory | ||
| ) | ||
|
|
||
| assert.throws(() => { | ||
| telephone.phoneNumber | ||
| }) | ||
| }) | ||
|
|
||
| }) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know anything about how this vocabulary is used in the Solid community it's history there or best practices that migh be in use, but I see a potential problem with this shape in the context of the vCard Ontology.
vcard:emailis a datatype property whilevcard:hasEmailis an object property.vcard:emailwill have a literal object or a blank node with avcard:valueproperty, itself a literal.vcard:hasEmailwill have a resource object or a blank node with avcard:hasValueproperty, itself a resouce.In this code, both of these are handled using the
Emailmapping class. Thst's not a problem, but then that class should be smarter.In any case, I don't think we are doing justice to the versatility of vCard. In my understanding, all of the following are valid shapes:
It is entirely possible to map any usage scenario to JavaScript classes using a combination of mapping properties and other logic. Here I'm just highlighting what seem like discrepancies. Happy to help with proposed programming constructs once there is clarity on what the shape we're mapping is.
If I'm calling out things that are irrelevant or have already been clarified then sorry.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Email shape that @hkir-dev has based this on is
https://github.com/solid/shape-generation-artefacts/tree/main/shapes/Email which itself originates in a SolidOS repo file, specifically:
https://github.com/SolidOS/contacts-pane/blob/main/src/ontology/forms.ttl
The idea of the Solid shape repo is to contain shapes that are in use in Solid projects. The present shapes in the shape artefacts repo originate from SolidOS GitHub repos.
I've noted a potential improvement in the Email shape, with use of
vcard:hasTypeinstead ofrdf:type.It has been noted by @timea-solid that a lot of change is underway in the existing original SolidOS ontology files - solid/shape-generation-artefacts#8. This may influence the idea of shapes hosted in a Solid shape repo being based on those used in current SolidOS repos?
Maybe we can review this with @jeswr?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Starting shapes based on SolidOS is a good way because it is where we are actually using them. And this is not 100% true. The shapes in SolidOS are actually RDF forms, which guide our interfaces, which just means that they are not written in SHACL or SHeX but using ui ontology.
Now, this being said, I am reworking the RDF forms in SolidOS because we are refactoring the UI. And I have noticed that the RDF forms in SolidOS are not all ontologically 100% correct. So, take them as guidance but improve them in the final shapes you create.
At some point, we will need to improve SolidOS and migrate data if need be, to adhere to correct ontologies. My work at the moment contains:
I am not changing any definition of any element since I am not an ontology expert.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@langsamu in this version of the VCard vocabulary (https://www.w3.org/2006/vcard/ns), both
emailandhasEmailare defined as object properties, and#emailis declared asowl:equivalentPropertyto#hasEmail. I’m unsure whether the object implementation should explicitly support both properties or rely on a reasoner to resolve the equivalence and handle only#hasEmail; however, for convenience, I added support for both.