weso / hercules-sync

Tools to synchronise data between the ontology files and Wikibase instance for the Hercules project at University of Murcia.
GNU General Public License v3.0
4 stars 1 forks source link

Decouple TripleElement from wdi #23

Open alejgh opened 4 years ago

alejgh commented 4 years ago

The current implementation of the LiteralElement and URIElement classes provide directly methods to translate to wdi datatypes and classes. For example:

class URIElement(TripleElement):

    ...

    @property
    def wdi_class(self) -> Union[Type[WDItemID], Type[WDProperty]]:
        """ Returns the wikidataintegrator class of the element.
        """
        assert self.etype in self.VALID_ETYPES
        return WDItemID if self.etype == 'item' else WDProperty

    @property
    def wdi_dtype(self) -> str:
        """ Returns the wikidataintegrator DTYPE of this element.
        """
        return self.wdi_class.DTYPE

    def to_wdi_datatype(self, **kwargs) -> Union[WDItemID, WDProperty]:
        return self.wdi_class(value=self.id, **kwargs)

This code should be refactored, so the wikidataintegrator objects are totally decoupled from the TripleElements. For example, the mappings module could be used to provide functions that can convert from one type to the other.