Example #1
0
def xml_utf8_sat(element, dom):
    if element.xml_children:
        element.pns_sat_articulated = []
        return pns_sat.articulate_re(
            ' '.join(xml_utf8.xml_cdatas(element)),
            element.pns_sat_articulated.append, element.pns_sat_language
            or dom.pns_sat_language)

    elif element.xml_first:
        element.pns_sat_articulated = []
        return pns_sat.articulate_re(
            element.xml_first, element.pns_sat_articulated.append,
            element.pns_sat_language or dom.pns_sat_language)
Example #2
0
def xml_utf8_sat (element, dom):
        if element.xml_children:
                element.pns_sat_articulated = []
                return pns_sat.articulate_re (
                        ' '.join (xml_utf8.xml_cdatas (element)),
                        element.pns_sat_articulated.append,
                        element.pns_sat_language or dom.pns_sat_language
                        )
                        
        elif element.xml_first:
                element.pns_sat_articulated = []
                return pns_sat.articulate_re (
                        element.xml_first, 
                        element.pns_sat_articulated.append,
                        element.pns_sat_language or dom.pns_sat_language
                        )
Example #3
0
def articulate_headers (
        headers, context, statement, lang,
        names=('subject', ), predicates=('from', 'to', 'date', )
        ):
        articulated = []
        subject = pns_model.pns_name (netstring.encode ((
                pns_sat.articulate_re (
                        headers.get (n), articulated.append, lang
                        ) for n in names
                )))
        for predicate in predicates:
                object = headers.get (predicate)
                if object == None:
                        continue
                
                statement ((subject, predicate, object), )

# Note about this implementation
# 
# This module implements a minimal MIME collector and UTF-8 transcoder 
# for PNS/SAT articulator, something practical to articulate plain text
# found in USENET and e-mail messages. 
#
# The purpose of pns_mime is to support the Enron mail and comp.lang.python
# test cases, indexing all mail made available by the famous case and
# do the same for as much as comp.lang.python is available on USENET.
#
# The CLI is a pipe that collects a stream of MIME messages from STDIN and 
# pipes out articulated PNS statements on STDOUT:
#
#   pns_mime < mime 1> pns
#
# or if provided the proper arguments:
#
#   pns_mime 127.0.0.1 3534 < mime
#
# to a PNS/TCP metabase.

# <mime>
#   <id/>
#   <subject/>
#   <from/>
#   <to/>
#   <content-type/>
# </mime>
#
Example #4
0
def articulate_headers(headers,
                       context,
                       statement,
                       lang,
                       names=('subject', ),
                       predicates=(
                           'from',
                           'to',
                           'date',
                       )):
    articulated = []
    subject = pns_model.pns_name(
        netstring.encode((pns_sat.articulate_re(headers.get(n),
                                                articulated.append, lang)
                          for n in names)))
    for predicate in predicates:
        object = headers.get(predicate)
        if object == None:
            continue

        statement((subject, predicate, object), )
Example #5
0
# -*- coding: CP1252 -*-

from allegra import netstring, loginfo, pns_sat

def log_articulated (articulated):
        for horizon, field, name, text in articulated:
                loginfo.log (text)
                loginfo.log (netstring.netoutline (name))

articulated = []
text = (
        'A just machine to make big decisions\n'
        'Programmed by fellows with compassion and vision'
        )
name = pns_sat.articulate_re (
        text, articulated.append, pns_sat.language ('en')
        )
log_articulated (articulated)

articulated = []
text = (
        "Ce qui se conçoit bien s'énonce clairement\n"
        "Et les mots pour le dire arrivent aisément"
        )
name = pns_sat.articulate_re (
        text, articulated.append, pns_sat.language ('fr')
        )
log_articulated (articulated)

articulated = []
text = (