예제 #1
0
파일: client.py 프로젝트: fserena/agora-gw
    def add_description(self, id, types):
        try:
            self._get_request('descriptions/{}'.format(id),
                              accept='text/turtle')
        except IOError:
            pass
        else:
            raise AttributeError(id)

        prefixes = self.agora.fountain.prefixes
        types = map(lambda t: URIRef(extend_uri(t, prefixes)), types)
        td = TD.from_types(id, types)
        try:
            response = self._post_request(
                'descriptions',
                td.to_graph(th_nodes={}).serialize(format='turtle'),
                content_type='text/turtle',
                accept='text/turtle')

            g = Graph()
            g.parse(StringIO(response), format='turtle')
            ted = TED.from_graph(g, loader=self.__loader)
            tds = ted.ecosystem.tds
            if len(tds):
                return list(tds).pop()
        except IOError:
            pass

        raise AttributeError(id)
예제 #2
0
    def add_description(self, id, types):
        # type: (basestring, iter) -> TED
        agora = self.agora
        if not all([t in agora.fountain.types for t in types]):
            raise TypeError('Unknown type')

        prefixes = agora.fountain.prefixes
        type_uris = [extend_uri(t, prefixes) for t in types]
        td = TD.from_types(types=type_uris, id=id)
        g = td.to_graph(th_nodes={})

        try:
            self.get_description(id)
        except AttributeError:
            ted = self.learn_descriptions(g)
            tds = ted.ecosystem.tds
            if len(tds):
                return list(tds).pop()
        else:
            raise AttributeError(id)