Skip to content

Commit

Permalink
feat: add romansh (DEV-867) (#193)
Browse files Browse the repository at this point in the history
  • Loading branch information
jnussbaum committed Jun 1, 2022
1 parent ed35902 commit 86d3e6a
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 234 deletions.
12 changes: 6 additions & 6 deletions docs/dsp-tools-create-ontologies.md
Expand Up @@ -141,16 +141,16 @@ By convention, property names start with a lower case letter.

`"labels": {"<language>": "<string>", ...}`

Collection of `labels` for the property as strings with language tag (currently "en", "de", "fr"
and "it" are supported).
Collection of `labels` for the property as strings with language tag (currently "en", "de", "fr", "it",
and "rm" are supported).

### Comments

(optional)

`"comments": { "<lang>": "<comment>", "<lang>": "<comment>", ... }`

Comments with language tags. Currently, "de", "en", "fr" and "it" are supported. The `comments` element is optional.
Comments with language tags. Currently, "de", "en", "fr", "it", and "rm" are supported. The `comments` element is optional.

### Super

Expand Down Expand Up @@ -780,8 +780,8 @@ By convention, resource names start with a upper case letter.

`"labels": {"<language>": "<string>", ...}`

Collection of `labels` for the resource as strings with language tag (currently "en", "de", "fr"
and "it" are supported).
Collection of `labels` for the resource as strings with language tag (currently "en", "de", "fr", "it",
and "rm" are supported).

### Super

Expand Down Expand Up @@ -844,7 +844,7 @@ resource can have as well as how many times the relation is established.

`"comments": { "<lang>": "<comment>", "<lang>": "<comment>", ... }`

Comments with language tags. Currently, "de", "en", "fr" and "it" are supported. The `comments` element is optional.
Comments with language tags. Currently, "de", "en", "fr", "it", and "rm" are supported. The `comments` element is optional.

Example for a resource definition:

Expand Down
8 changes: 4 additions & 4 deletions docs/dsp-tools-create.md
Expand Up @@ -167,7 +167,7 @@ The longname is a string that provides the full name of the project.

`"descriptions": {"<lang>": "<string>", ...}`

The description is represented as a collection of strings with language tags (currently "en", "de", "fr" and "it" are
The description is represented as a collection of strings with language tags (currently "en", "de", "fr", "it", and "rm" are
supported). It is the description of the project.

### Keywords
Expand Down Expand Up @@ -201,9 +201,9 @@ A node of a list may have the following elements:

- _name_: Name of the node as string. It is mandatory and has to be unique within the list.
- _labels_: Label with language tags in the form `{ "<lang>": "<label>", "<lang>": "<label>", ... }`. The `labels`
element is mandatory. It needs to specify at least one language. Currently, "de", "en", "fr" and "it" are supported.
element is mandatory. It needs to specify at least one language. Currently, "de", "en", "fr", "it", and "rm" are supported.
- _comments_: Comment with language tags in the form `{ "<lang>": "<comment>", "<lang>": "<comment>", ... }`.
Currently, "de", "en", "fr" and "it" are supported. The `comments` element is mandatory for the root node of the list.
Currently, "de", "en", "fr", "it", and "rm" are supported. The `comments` element is mandatory for the root node of the list.
For all other nodes, it is optional. If not used, the element should be omitted.
- _nodes_: Array of sub-nodes. The `nodes` element is optional and can be omitted in case of a flat list.

Expand Down Expand Up @@ -360,7 +360,7 @@ A group definition has the following elements:

- _name_: name of the group, mandatory
- _descriptions_: description of the group with language tags in the form `"descriptions": {"<lang>": "<string>", ...}` (
currently "en", "de", "fr" and "it" are supported), mandatory
currently "en", "de", "fr", "it", and "rm" are supported), mandatory
- _selfjoin_: true if users are allowed to join the group themselves, false if an administrator has to add the users,
optional
- _status_: true if the group is active, false if the group is inactive, optional
Expand Down
2 changes: 1 addition & 1 deletion knora/dsplib/models/group.py
Expand Up @@ -54,7 +54,7 @@ class Group(Model):
Name of the group
descriptions : LangString
Group descriptions in a given language (Languages.EN, Languages.DE, Languages.FR, Languages.IT).
Group descriptions in a given language (Languages.EN, Languages.DE, Languages.FR, Languages.IT, Languages.RM).
project : str | project
either the IRI of a project [get only, cannot be modified after creation of instance]
Expand Down
5 changes: 5 additions & 0 deletions knora/dsplib/models/langstring.py
Expand Up @@ -10,6 +10,7 @@ class Languages(Enum):
DE = 'de'
FR = 'fr'
IT = 'it'
RM = 'rm'


LangStringParam = Optional[Union[dict[Union[Languages, str], str], str]]
Expand Down Expand Up @@ -224,6 +225,8 @@ def fromJsonLdObj(cls, obj: Optional[Union[list[dict[str, str]], str]]) -> 'Lang
lstrs[Languages.FR] = o.get('@value')
elif lang == 'it':
lstrs[Languages.IT] = o.get('@value')
elif lang == 'rm':
lstrs[Languages.RM] = o.get('@value')
else:
if o.get('@value') is not None:
return cls(o.get('@value'))
Expand All @@ -250,6 +253,8 @@ def fromJsonObj(cls, obj: Optional[Any]) -> 'LangString':
lstrs[Languages.FR] = o.get('value')
elif lang == 'it':
lstrs[Languages.IT] = o.get('value')
elif lang == 'rm':
lstrs[Languages.RM] = o.get('value')
else:
if o.get('value') is not None:
return cls(o.get('value'))
Expand Down
4 changes: 2 additions & 2 deletions knora/dsplib/schemas/lists-only.json
Expand Up @@ -7,7 +7,7 @@
"langstring": {
"type": "object",
"patternProperties": {
"^(en|de|fr|it)": {
"^(en|de|fr|it|rm)$": {
"type": "string"
}
},
Expand All @@ -19,7 +19,7 @@
"comment": {
"type": "object",
"patternProperties": {
"^(en|de|fr|it)": {
"^(en|de|fr|it|rm)$": {
"type": "string"
}
},
Expand Down
4 changes: 2 additions & 2 deletions knora/dsplib/schemas/ontology.json
Expand Up @@ -7,7 +7,7 @@
"langstring": {
"type": "object",
"patternProperties": {
"^(en|de|fr|it)": {
"^(en|de|fr|it|rm)$": {
"type": "string"
}
},
Expand Down Expand Up @@ -126,7 +126,7 @@
},
"lang": {
"type": "string",
"pattern": "^(en|de|fr|it)"
"pattern": "^(en|de|fr|it|rm)$"
},
"groups": {
"type": "array",
Expand Down
2 changes: 1 addition & 1 deletion knora/dsplib/schemas/properties-only.json
Expand Up @@ -7,7 +7,7 @@
"langstring": {
"type": "object",
"patternProperties": {
"^(en|de|fr|it)": {
"^(en|de|fr|it|rm)$": {
"type": "string"
}
},
Expand Down
2 changes: 1 addition & 1 deletion knora/dsplib/schemas/resources-only.json
Expand Up @@ -7,7 +7,7 @@
"langstring": {
"type": "object",
"patternProperties": {
"^(en|de|fr|it)": {
"^(en|de|fr|it|rm)$": {
"type": "string"
}
},
Expand Down
25 changes: 2 additions & 23 deletions knora/dsplib/utils/excel_to_json_lists.py
Expand Up @@ -220,26 +220,6 @@ def simplify_name(value: str) -> str:
return simplified_value


def check_language_code(lang_code: str) -> bool:
"""
Checks if a given language code is valid. The code is valid if it is listed in language-codes-3b2_csv.csv. This
file provides all ISO 639-1 and ISO 639-2 language codes.
Args:
lang_code: the language code to be checked
Returns:
True if valid, False if not
"""
current_dir = os.path.dirname(os.path.realpath(__file__))
with open(os.path.join(current_dir, 'language-codes-3b2_csv.csv'), 'r') as language_codes_file:
language_codes = csv.reader(language_codes_file, delimiter=',')
for row in language_codes:
if lang_code in row:
return True
return False


def make_root_node_from_args(
excelfiles: list[str],
listname_from_args: Optional[str],
Expand All @@ -264,9 +244,8 @@ def make_root_node_from_args(
basename = os.path.basename(filename)
lang_specific_listname, lang_code = os.path.splitext(basename)[0].rsplit('_', 1)

if not check_language_code(lang_code):
print(f'Invalid language code "{lang_code}" is used. Only language codes from ISO 639-1 ',
f'and ISO 639-2 are accepted.')
if lang_code not in ['en', 'de', 'fr', 'it', 'rm']:
print(f'Invalid language code "{lang_code}" is used. Only en, de, fr, it, and rm are accepted.')
quit()

listname_from_lang_code[lang_code] = lang_specific_listname
Expand Down
185 changes: 0 additions & 185 deletions knora/dsplib/utils/language-codes-3b2_csv.csv

This file was deleted.

0 comments on commit 86d3e6a

Please sign in to comment.