Search code examples
pythonrakeontologyowlready

DataProperty from ontology using keywords from rake and owlready2


I am trying to extract the value of a dataProperty: if I test this ----> it works !

keywords="Tunisia"
key="*"+keywords+"*"
country= onto.search(iri=key)
country
print(country[1].recovered, country[1].cases) ------> ['216'] ['949']

But when I try this :

        r.extract_keywords_from_text("Tunisia")
        words=r.get_ranked_phrases()
        keywords=str(words)
        key="*"+keywords+"*"
        country= onto.search(iri=key)
        if len(country)>0:

            print(country[1].recovered,country[1].cases)

        else:
            print("no cases")

this error appears : Traceback (most recent call last):

File "", line 8, in print(country[1].recovered,country[1].cases)

File "C:\Users\stef info\Anaconda3\lib\site-packages\owlready2\prop.py", line 243, in getattr raise AttributeError("Property can only have annotation property values!")

AttributeError: Property can only have annotation property values!

how can I fix it!


Solution

  • I fixed it by replacing

           keywords=str(words)
           key="*"+keywords+"*"
    

    by

            key="*"+words[0]+"*"