Exemplo n.º 1
0
 def get_clauses(self, aid, saf):
     if not 'tokens' in saf and 'clauses' in saf:
         return
     from saf.saf import SAF
     saf = SAF(saf)
     tokens = saf.resolve()
     for token in tokens:
         token["aid"] = aid
         yield token
Exemplo n.º 2
0
 def get_clauses(self, aid, saf):
     if not 'tokens' in saf and 'clauses' in saf:
         return
     from saf.saf import SAF
     saf = SAF(saf)
     tokens = saf.resolve()
     for token in tokens:
         token["aid"] = aid
         yield token
Exemplo n.º 3
0
    def form_valid(self, form):
        from saf.saf import SAF
        from saf.clause import match_codes
        # Get parse
        sent = form.cleaned_data['sentence']
        parse = get_adhoc_result('clauses_en', sent)
        saf = SAF(parse)
        tokens  = saf._tokens

        # add codebook
        if 'codebook' in self.request.GET:
            codebook = Codebook.objects.get(pk=int(self.request.GET['codebook']))
            saf.saf['codes'] = list(match_codes(saf, codebook))

        # get tokens and clauses
        tokens = saf.resolve()
        clauses = list(saf.get_reduced_clauses())

        # add frames
        for clause in clauses:
            add_frames(saf, clause)

        # provide list of all codes
        codes = set(flatten(t.get('codes', []) for t in tokens))

        # resolve all places in the clauses
        for clause in clauses:
            for place in ['source', 'subject', 'predicate']:
                clause[place] = saf.resolve(clause[place])
        print clauses
        # make tree
        from saf import visualize
        tree = visualize.get_png_bytes(saf)


        ctx = dict(form=form,
                   clauses=clauses,
                   tokens=tokens,
                   saf=json.dumps(saf.saf, indent=2),
                   codes=codes,
                   tree=tree)

        return self.render_to_response(self.get_context_data(**ctx))
Exemplo n.º 4
0
    def form_valid(self, form):
        from saf.saf import SAF
        from saf.clause import match_codes
        # Get parse
        sent = form.cleaned_data['sentence']
        parse = get_adhoc_result('clauses_en', sent)
        saf = SAF(parse)
        tokens = saf._tokens

        # add codebook
        if 'codebook' in self.request.GET:
            codebook = Codebook.objects.get(
                pk=int(self.request.GET['codebook']))
            saf.saf['codes'] = list(match_codes(saf, codebook))

        # get tokens and clauses
        tokens = saf.resolve()
        clauses = list(saf.get_reduced_clauses())

        # add frames
        for clause in clauses:
            add_frames(saf, clause)

        # provide list of all codes
        codes = set(flatten(t.get('codes', []) for t in tokens))

        # resolve all places in the clauses
        for clause in clauses:
            for place in ['source', 'subject', 'predicate']:
                clause[place] = saf.resolve(clause[place])
        print clauses
        # make tree
        from saf import visualize
        tree = visualize.get_png_bytes(saf)

        ctx = dict(form=form,
                   clauses=clauses,
                   tokens=tokens,
                   saf=json.dumps(saf.saf, indent=2),
                   codes=codes,
                   tree=tree)

        return self.render_to_response(self.get_context_data(**ctx))