-
Notifications
You must be signed in to change notification settings - Fork 100
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
Code duplication: determine an entity type by looking at the format of its id #424
Comments
Yes, indeed it's a bit of a mess. The choice have been done at the beggining of WikidataToolkit to create URIs for each Wikibase datamodel enumeration (datatypes, entity types...), leading to this duplication. We have two options here:
I would slightly prefer 2. because it is less disruptive for the library user. In this case we should probably have a method that returns the Datatype IRI. This method could be public in the |
Option 2 is fine with me too. |
Hi Is this issue still open? I was planning to work on it. Would appreciate if you could provide some pointers on it. From first look, it seems that creating a function Then we can replace the switch cases in The above mentioned function could have a flag to indicate whether JSON string should be returned, and we could default to IRIs or other way round. This way we might not even need to add a public function for transforming between JSON string and IRIs since we are preserving the old functions and just abstracting out the conversion logic to a common function. What are your thoughts about it? |
Hi! Yes, the issue is still open. Thank you for being interested in it! For me |
HI @Tpt,
Although, if we return Alternatively, we could have a package-private / protected function that has the switch-case logic and can return JSON or IRI based on flag. And then we have a public function wrapper around it, that just returns IRI protected static String guessEntityTypeFromId(String id, boolean returnJsonEntity) {
// switch-case logic here
}
public static String guessEntityTypeFromId(Stirng id) {
return guessEntityTypeFromId(id, false);
} This way we can get the IRI-JSON flag without ever exposing JSON serialization internals. |
It sounds like a great plan! Thank you! |
There are at least two places in our code where we try to guess the type of an entity based on the format of its id:
Wikidata-Toolkit/wdtk-datamodel/src/main/java/org/wikidata/wdtk/datamodel/implementation/EntityIdValueImpl.java
Lines 134 to 162 in ac2692a
and
Wikidata-Toolkit/wdtk-rdf/src/main/java/org/wikidata/wdtk/rdf/PropertyRegister.java
Lines 199 to 229 in d76e8ee
That is a problem: it is easy to forget to update one of them (it caused #407).
We should expose this functionality publicly in the
wdtk-datamodel
module. This raises questions:EntityIdValue
interface offers… But then we probably need other static methods to help convert between all these formats? It's a bit of a mess :-/The text was updated successfully, but these errors were encountered: