Skip to content

Commit

Permalink
fix rdf langstring handling
Browse files Browse the repository at this point in the history
  • Loading branch information
s-tittel committed Jul 16, 2024
1 parent 54572d6 commit 0f5cc70
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ data-values | RDF triples (e.g. a turtle string) to use as existing data graph t
data-values-url | When `data-values` is not set, the data graph triples are loaded from this URL
data-values-subject | The subject (id) of the generated data. If this is not set, a blank node with a new UUID is created. If `data-values` or `data-values-url` is set, this id is also used to find the root node in the data graph to fill the form
data-values-namespace | RDF namespace to use when generating new RDF subjects. Default is empty, so that subjects will be blank nodes.
data-language | Language to use if shapes contain langStrings, e.g. in `sh:name` or `rdfs:label`. Default is [`navigator.language`](https://www.w3schools.com/jsref/prop_nav_language.asp)
data-language | Language to use if shapes contain langStrings, e.g. in `sh:name` or `rdfs:label`. Default is [`navigator.language`](https://developer.mozilla.org/en-US/docs/Web/API/Navigator/language) with fallback to [`navigator.languages`](https://developer.mozilla.org/en-US/docs/Web/API/Navigator/languages)
data-loading | Text to display while the web component is initializing. Default: `"Loading..."`
data‑ignore‑owl‑imports | By default, `owl:imports` URLs are fetched and the resulting RDF triples are added to the shapes graph. Setting this attribute to any value disables this feature
data-view | When set, turns the web component into a viewer that displays the given data graph without editing functionality
Expand Down Expand Up @@ -111,7 +111,7 @@ Class hierarchies can be built using `rdfs:subClassOf` or `skos:broader`.
### Validation
In edit mode, `<shacl-form>` validates the constructed data graph using the library [rdf-validate-shacl](https://github.com/zazuko/rdf-validate-shacl) and displays validation results as icons next to the respective form fields.
In edit mode, `<shacl-form>` validates the constructed data graph using the library [shacl-engine](https://github.com/rdf-ext/shacl-engine) and displays validation results as icons next to the respective form fields.
### Data graph binding
Expand Down Expand Up @@ -182,7 +182,7 @@ When adding a new attribution, `<shacl-form>` renders a dropdown to let the user
When binding an existing data graph to the form, the `sh:or` constraint is tried to be resolved depending on the respective data value:
- For RDF literals, an `sh:or` option with a matching `sh:datatype` is chosen
- For blank nodes or named nodes, the `rdf:type` of the value is tried to be matched with a node shape having a corresponding `sh:targetClass` or with a property shape having a corresponding `sh:class`
- For blank nodes or named nodes, the `rdf:type` of the value is tried to be matched with a node shape having a corresponding `sh:targetClass` or with a property shape having a corresponding `sh:class`. If there is no `rdf:type` but a `sh:nodeKind` of `sh:IRI`, the id of the the node is used as the value.
### SHACL shape inheritance
Expand Down
2 changes: 1 addition & 1 deletion demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<script type="importmap">
{
"imports": {
"@ulb-darmstadt/shacl-form/": "https://cdn.jsdelivr.net/npm/@ulb-darmstadt/[email protected].7/dist/"
"@ulb-darmstadt/shacl-form/": "https://cdn.jsdelivr.net/npm/@ulb-darmstadt/[email protected].8/dist/"
}
}
</script>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ulb-darmstadt/shacl-form",
"version": "1.4.7",
"version": "1.4.8",
"description": "SHACL form generator",
"main": "dist/form-default.js",
"module": "dist/form-default.js",
Expand Down
12 changes: 9 additions & 3 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class Config {
classInstanceProvider: ClassInstanceProvider | undefined
prefixes: Prefixes = {}
editMode = true
languages: string[] = Array.from(navigator.languages)
languages: string[]

dataGraph = new Store()
lists: Record<string, Term[]> = {}
Expand All @@ -44,6 +44,12 @@ export class Config {
constructor(theme: Theme, form: HTMLElement) {
this.theme = theme
this.form = form
this.languages = [... new Set(navigator.languages.flatMap(lang => {
if (lang.length > 2) {
return [lang, lang.substring(0, 2)]
}
return lang
}))]
}

updateAttributes(elem: HTMLElement) {
Expand All @@ -61,12 +67,12 @@ export class Config {
this.attributes.valuesSubject = this.attributes.valueSubject
}
if (atts.language) {
// remove preferred language from list of navigator languages
const index = this.languages.indexOf(atts.language)
if (index > -1) {
// remove preferred language from the list of languages
this.languages.splice(index, 1)
}
// now prepend preferred language at start of list of navigator languages
// now prepend preferred language at start of the list of languages
this.languages.unshift(atts.language)
}
}
Expand Down

0 comments on commit 0f5cc70

Please sign in to comment.