コード例 #1
0
 def decompose_representation(self, representation: Representation):
     chi = representation.get_character()
     character_products = {
         character: self.get_product(chi, character)
         for character in self.characters
     }
     return character_products
コード例 #2
0
 def represent_atom_default(self, page):
     content = render_atom(self.req,
                           page.title,
                           WikiPage.title_to_path(page.title),
                           page.get_posts(count=20),
                           include_content=True,
                           use_published_date=True)
     return Representation(content, 'text/xml; charset=utf-8')
コード例 #3
0
    def represent_html_default(self, page):
        if page.metadata['content-type'] != 'text/x-markdown':
            content = WikiPage.remove_metadata(page.body)
            content_type = '%s; charset=utf-8' % str(
                page.metadata['content-type'])
            return Representation(content, content_type)

        if page.metadata.get('redirect', None) is not None:
            return Representation(None, None)
        else:
            redirected_from = self.req.cookies.get('ecogwiki_redirect_from')
            self.res.delete_cookie('ecogwiki_redirect_from')
            content = {
                'page': page,
                'message': self.res.headers.get('X-Message', None),
                'redirected_from': redirected_from,
            }
            if page.metadata.get('schema', None) == 'Blog':
                content['posts'] = page.get_posts(count=50)
            return TemplateRepresentation(content, self.req,
                                          self._findTemplateForWikipage(page))
コード例 #4
0
    def __init__(self, dim=4, n_actions=4, action_reps=None):
        super().__init__(n_actions, dim)
        self.dim = dim

        if action_reps is None:
            self.action_reps = [
                Representation(dim=self.dim) for _ in range(n_actions)
            ]
        else:
            if len(action_reps) != n_actions:
                raise Exception(
                    "Must pass an action representation for every action.")
            if not all([rep.dim == self.dim for rep in self.action_reps]):
                raise Exception(
                    "Action representations do not act on the dimension of the latent space."
                )
            self.action_reps = action_reps

        self.reset()
コード例 #5
0
 def represent_atom_default(self, data):
     content = render_atom(self.req, 'Changes', 'sp.changes', data['pages'])
     return Representation(content, 'text/xml; charset=utf-8')
コード例 #6
0
 def represent_atom_default(self, pages):
     content = render_atom(self.req, 'Title index', 'sp.index', pages)
     return Representation(content, 'text/xml; charset=utf-8')
コード例 #7
0
 def represent_txt_default(self, page):
     return Representation(page.body, 'text/plain; charset=utf-8')
コード例 #8
0
 def __init__(self, graph: nx.Graph, representation: Representation):
     self.representation = representation
     self.edges = graph.edges
     self._dim = representation.dim()
     self._identity = np.eye(self._dim)
     self._size = graph.number_of_nodes() * self._dim