Skip to content
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

Multiple language literals cannot be accessed #91

Open
a3li opened this issue Feb 26, 2014 · 3 comments
Open

Multiple language literals cannot be accessed #91

a3li opened this issue Feb 26, 2014 · 3 comments

Comments

@a3li
Copy link
Contributor

a3li commented Feb 26, 2014

In my ontology, have no assurance that the prefLabels have languages:

:thing1  skos:prefLabel
    "Thing" .
:thing2  skos:prefLabel
    "Thing"@en ;
    "Ding"@de .

So I'm trying to create a "LabelledModel" that can work with either:

@RdfProperty(value="skos:prefLabel", language="")
protected String skosPrefLabel;
@RdfProperty(value="skos:prefLabel", language="de")
protected String skosPrefLabelDE;
@RdfProperty(value="skos:prefLabel", language="en")
protected String skosPrefLabelEN;

Currently, RdfGenerator.fromRDF maintains the aAccessMap as PropertyURI -> Field 1:1 mapping. The way I understand the problem, I can only have one field linked to a property, whereas to capture the different language literals, I need multiple.

The current code threw exceptions trying to cast a String to a Collection?!
I tried to fix this in a3li/Empire@2f3723d
As I'm digging really deep into the core, I'd appreciate some comments before submitting a pull request.

@mhgrove
Copy link
Owner

mhgrove commented Feb 26, 2014

Yes, the expectation originally was a 1:1 mapping from field unless specified otherwise via an annotation. Your commit seems ok, but I think there are cases where you don't know all the language tags you are interested in a priori. In those cases, you probably want all of them (on the bean), and a way at runtime to get a specific version w/ a given language.

So it might be the case that the normal behavior is fine, but that there is a new 'primitive' LanguageString which under the hood is a collection, but has a toString(final String theLanguage) method to get the string w/ the appropriate language. That might work for both use cases.

@a3li
Copy link
Contributor Author

a3li commented Feb 26, 2014

Sounds good as well.
Can you implement that 'primitive' or if not, give me a few hints on how to do it?

@mhgrove
Copy link
Owner

mhgrove commented Feb 26, 2014

I can, but it won't be any time soon. If you need it in the near future, I'd recommend doing it yourself.

It should be pretty straightforward. ToObjectFunction handles, generally, RDF -> Java. Give the property->field mapping, it gets all the values for that property, so you have Collection<Value> and when the field is a Collection will turn that into a Collection<Object>

When the field is not a Collection, it tries to see if it's a list of literals, and if LANG_AWARE is enabled, it removes all literals which are not tagged w/ the correct language, otherwise, it removes all literals with a language tag.

It's probably there that you might put in the logic to do something smarter w/ the conversion of the list of lang-tagged literals.

ValueToObject mostly handles direct conversion of RDF Value -> Object, so it's possible something might go there, but you can probably get away with only modifying ToObjectFunction

The opposite conversion is easier, you'd just need an else if (LanguageString.class.isAssignableFrrom(aValue.class)) in RdfGenerator#asRdf(Object) and convert the object into the appropriate number of statements there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants