jessicacardoso

relationship_strength

Jan 21st, 2020
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.05 KB | None | 0 0
  1. def get_relationship_strength(self, entity):
  2.         try:
  3.             query = str(''' PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
  4.                            prefix rn: <http://www.daslab.inf.puc-rio.br/ontologies/RelationshipNotes#>
  5.                            select ?relation ?rest ?strength where {{
  6.                                ?relation a rn:Relationship.
  7.                                ?relation rdf:first <{}>.
  8.                                ?relation rdf:rest ?rest.
  9.                                ?relation rn:relationshipStrength ?strength.
  10.                            }}
  11.                            '''.format(entity))
  12.             res = req.get(self.url + up.quote(query), auth=self.auth).json()
  13.             strengths = {}
  14.             for c in res['results']['bindings']:
  15.                 strengths[c['rest']['value']] = c['strength']['value']
  16.             return strengths
  17.         except Exception as e:
  18.             Logger.log.error("Cannot query relationship strength, because: " + str(e), exc_info=True)
  19.             return {}
Add Comment
Please, Sign In to add comment