Skip to content

The DublinCore class

gamslib.objectcsv.dublincore.DublinCore

DublinCore(path, lookup_order=('en', 'de', 'fr', 'es', 'it'))

Represents data from DC.xml.

Provides methods to access DC data with language support, and to validate the minimal GAMS requirements for the DX.XML file.

Initialize and parse the DC.xml file.

PARAMETER DESCRIPTION
path

Path to the DC.xml file.

TYPE: Path

lookup_order

Preferred language order for fallback.

TYPE: tuple DEFAULT: ('en', 'de', 'fr', 'es', 'it')

UNSPECIFIED_LANG class-attribute instance-attribute

UNSPECIFIED_LANG = 'unspecified'

path instance-attribute

path = path

lookup_order instance-attribute

lookup_order = list(lookup_order)

remove_linebreaks classmethod

remove_linebreaks(text)

Remove linebreaks from a string.

PARAMETER DESCRIPTION
text

The string to remove linebreaks from.

TYPE: str

RETURNS DESCRIPTION
str

The string without linebreaks.

TYPE: str

get_en_element

get_en_element(name, default='')

Return the value(s) of a Dublin Core element in English. If no English value is found, return the default value.

PARAMETER DESCRIPTION
name

The name of the element without namespace (e.g. "title").

TYPE: str

default

Default value if element is missing.

TYPE: str DEFAULT: ''

RETURNS DESCRIPTION
list[str]

list[str]: The value(s) of the element as a list of strings.

RAISES DESCRIPTION
ValueError

If the element name is not a valid Dublin Core element.

get_en_element_as_str

get_en_element_as_str(name, default='')

Return all entries of a Dublin Core element in English as string.

Entries are separated by '; '.

Delimi

PARAMETER DESCRIPTION
name

The name of the element without namespace (e.g. "title").

TYPE: str

default

Default value if element is missing.

TYPE: str DEFAULT: ''

RETURNS DESCRIPTION
str

The joined value(s) of the element as a string. Multiple values

TYPE: str

str

are separated by ';'.

RAISES DESCRIPTION
ValueError

If the element name is not a valid Dublin Core element.

get_element

get_element(name, preferred_lang='en', default='')

Return the value(s) of a Dublin Core element as a list of strings.

If no entry in the preferred language is available, the function will search for entries in another language, depending on the lookup_order set during object creation. If no entry is found with a specified language, the function checks for an entry with no 'xml:lang' attribute. If still no value is found, the default value will be returned (as a list).

PARAMETER DESCRIPTION
name

The name of the element without namespace (e.g. "title").

TYPE: str

preferred_lang

The preferred language of the element (e.g. "de").

TYPE: str DEFAULT: 'en'

default

The default value to return if no value is found.

TYPE: str DEFAULT: ''

RETURNS DESCRIPTION
list[str]

list[str]: The value(s) of the element as a list of strings.

RAISES DESCRIPTION
ValueError

If the element name is not a valid Dublin Core element.

get_element_as_str

get_element_as_str(name, preferred_lang='en', default='')

Return the value(s) of a Dublin Core element as a string.

PARAMETER DESCRIPTION
name

The name of the element without namespace.

TYPE: str

preferred_lang

The preferred language of the element.

TYPE: str DEFAULT: 'en'

default

The default value to return if no value is found.

TYPE: str DEFAULT: ''

RETURNS DESCRIPTION
str

The value(s) as a single string. For 'rights', formats as "name (url)"

TYPE: str

str

if two values are present; otherwise, values are joined with ';'.

get_element_all_langs

get_element_all_langs(name)

Return all values of a Dublin Core element for all languages.

This includes unspecified languages.

PARAMETER DESCRIPTION
name

The name of the element without namespace (e.g. "title").

TYPE: str

RETURNS DESCRIPTION
list[str]

list[str]: A list of all values for the element in all available

list[str]

languages (including unspecified).

list[str]

If the element is not found, an empty list is returned.

RAISES DESCRIPTION
ValueError

If the element name is not a valid Dublin Core element.

validate

validate()

Validate the Dublin Core file.

RAISES DESCRIPTION
ValueError

If the Dublin Core file is invalid.