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

Error running the Getting started example, unhashable type: 'SPARQLConnector #210

Open
sky-2002 opened this issue Jul 10, 2023 · 3 comments
Labels
bug Something isn't working

Comments

@sky-2002
Copy link

sky-2002 commented Jul 10, 2023

First of all, thanks a lot for this repo, @bsteenwi @GillesVandewiele @rememberYou .

🐛 Bug

TypeError: unhashable type: 'SPARQLConnector' when running example code given in readme. The error arises out of the following code: responses = [self.connector.fetch(query) for query in queries] present here.

I also tried installing from the develop branch as was mentioned in this issue. But I am still getting the error.

Expected Behavior

No errors.

Current Behavior

The line embeddings, literals = transformer.fit_transform(knowledge_graph, entities) results into the error - TypeError: unhashable type: 'SPARQLConnector'.

Steps to Reproduce

I tried the code given in the readme file on the repo.

# Create our transformer, setting the embedding & walking strategy.
transformer = RDF2VecTransformer(
    Word2Vec(epochs=10),
    walkers=[RandomWalker(4, 10, with_reverse=False, n_jobs=2)],
    # verbose=1
)
# Get our embeddings.
embeddings, literals = transformer.fit_transform(knowledge_graph, entities)
print(embeddings)

Environment

  • Operating system: Ubuntu 22.04.2
  • pyRDF2Vec version: 0.2.3
  • Python version: 3.11.3

Possible Solution

For me, changing this line in connectors.py:

@cachedmethod(operator.attrgetter("cache"), key=partial(hashkey, "fetch"))
def fetch(self, query: str) -> Response:

to this:

@cachedmethod(operator.attrgetter("cache"))
def fetch(self, query: str) -> Response:

solved the issue. But I think a solution for error free installation is needed, without needing to change this line, happy to contribute if guided.

@sky-2002 sky-2002 added the bug Something isn't working label Jul 10, 2023
@rememberYou
Copy link
Collaborator

Hi @sky-2002, thank you very much for your feedback! :-)

It's not the first time I've seen some users encounter problems with the cached fetch method. I know that back in the day they didn't specify a hash key for it, but that it was problematic at some point.

Thanks for the suggestion as well.

@bsteenwi
Copy link
Collaborator

hmm @rememberYou,

you already solved that issue right?:
The commit d039a702c9b072983b5f60ba7892b8d7a2cf1993 on the develop branch has fixed the issue with cachetool.

I can't find any reference to @cachedmethod(operator.attrgetter("cache"), key=partial(hashkey, "fetch"))

@rememberYou
Copy link
Collaborator

@bsteenwi Oh yes indeed, I can see that the use of key=partial(hashkey, "fetch")) has already been removed from the develop branch since quite a while.

@sky-2002 In principle, this error should no longer be present. Did you clone the repository?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants