samvera-labs / ldpath

Ruby parser for the LDPath language
http://marmotta.apache.org/ldpath/language.html
Other
9 stars 5 forks source link

Optionally have ldpath return RDF::Literals instead of Strings #16

Open elrayle opened 4 years ago

elrayle commented 4 years ago

Description

An ldpath program can request a result in a specific language, but if language is not specified, all literals will be returned for all languages. Since the results are returned as strings, the language tagging is lost. This prevents the caller from processing the results based on language.

This can be ameliorated by allowing the #evaluate method to have an optional parameter requesting that results be returned as RDF::Literals instead of Strings.

Rationale

Callers of ldpath may want to get all possible values for all languages and have language specific processing in the calling app.

Use Case

Ldpath is used to get values for two related properties. Each property's values are sorted by language making the two sets of property results align by language.

The values can be requested by language, but that assumes you know in advance all the possible languages.

NOTE: This sorting is happening in the calling app. Without language tagging, this type of sorting cannot be done.

Desired Ordering

term = ["dried milk", "getrocknete Milch", "lait en poudre"]
desc = ["powdery", "Pulverförmig", "poudreux"]

Undesired Ordering

term = ["dried milk", "getrocknete Milch", "lait en poudre"]
desc = ["poudreux", "powdery", "Pulverförmig"]

Expected Results

results = ldpath_program.evaluate(subject_uri, context: graph, limit_to_context: true, literal_results: true)
results # [RDF::Literal<"milk"@en>, RDF::Literal<"milche"@de>, RDF::Literal<"lait"@fr>]

Actual Results

literal_results is not a parameter in the current implementation

results = ldpath_program.evaluate(subject_uri, context: graph, limit_to_context: true)
results # ["milk", "milche", "lait"]
elrayle commented 4 years ago

@cbeer How hard do you think it would be to do this? I took a quick look and it wasn't apparent to me where results are converted from RDF::Literals to Strings.

elrayle commented 4 years ago

Looks like the conversion from RDF::Literal to String happens in field_mapping #transform_value