Exemplo n.º 1
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Usage:
python graph/graph.py <PATH TO CONFIG.INI> <TYPE>
type: ii | it | tt
"""

from scripts.environment import load

if __name__ == "__main__":
    import sys
    load(sys.argv[-2])

    from scripts.model import *
    from mako.template import Template
    
    type = sys.argv[-1]
    if type == "ii":
        edges = model.meta.Session.query(model.IdeaGraphEdge).all()
    elif type == "it":
        edges = model.meta.Session.query(model.IdeaThinkerGraphEdge).all()
    elif type == "tt":
        edges = model.meta.Session.query(model.ThinkerGraphEdge).all()
    else:
        raise Exception("unrecognized type")
    
    graph = Template(filename='graph/graph.txt', default_filters=['decode.utf8'])
    print graph.render_unicode(graph=edges).encode('utf-8','replace')

else:
Exemplo n.º 2
0
from scripts.environment import load
import re

if __name__ == "__main__":
    import sys
    config = load(sys.argv[-1])
    from scripts.model import *
    from mako.template import Template
    from sqlalchemy.sql.expression import and_

    def calc(type=Idea, graph_type=IdeaGraphEdge):
        q = meta.Session.query(type)
        edgeq = meta.Session.query(graph_type).\
                     join((type, type.ID==graph_type.cons_id)).\
                     filter(type.sep_dir != '')
        sep_ideas = q.filter(type.sep_dir != '').all()

        for ante in sep_ideas:
            f = ante.get_filename(config['app_conf']['corpus'])
            if not f:
                continue

            f = open(f)
            txt = f.read()
            edges = edgeq.filter(graph_type.ante == ante).all()
            for edge in edges:
                try:
                    # find how many times term occurs in article
                    edge.occurs_in = len(
                        re.findall(edge.cons.searchpattern, txt))
                    print "<%s, %s> = %d" % (ante.label, edge.cons.label,
Exemplo n.º 3
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from scripts.environment import load

if __name__ == "__main__":
    import sys
    load(sys.argv[-1])

    from scripts.model import *
    from mako.template import Template
    
    node_q = model.meta.Session.query(model.Node)
    thinker_q = model.meta.Session.query(model.Thinker)
    profession_q = model.meta.Session.query(model.Profession)
    nationality_q = model.meta.Session.query(model.Nationality)
    
    nodes = node_q.all()
    thinkers = thinker_q.all()
    professions = profession_q.all()
    nationalities = nationality_q.all()
    
    owl = Template(filename='/Users/inpho/api/scripts/owl/owl.xml',
                   default_filters=['decode.utf8', 'u', 'x'])
    print owl.render_unicode(nodes=nodes, thinkers=thinkers, 
               professions=professions, nationalities=nationalities).encode('utf-8',
               'replace')

else:
    raise Exception("Must be called from command line")
Exemplo n.º 4
0
from scripts.environment import load
import re

if __name__ == "__main__":
    import sys
    config = load(sys.argv[-1])
    from scripts.model import *
    from mako.template import Template
    from sqlalchemy.sql.expression import and_

    def calc(type=Idea, graph_type=IdeaGraphEdge):
        q = meta.Session.query(type)
        edgeq = meta.Session.query(graph_type).\
                     join((type, type.ID==graph_type.cons_id)).\
                     filter(type.sep_dir != '')
        sep_ideas = q.filter(type.sep_dir != '').all()
        
        for ante in sep_ideas:
            f = ante.get_filename(config['app_conf']['corpus'])
            if not f:
                continue
        
            f = open(f) 
            txt = f.read()
            edges = edgeq.filter(graph_type.ante == ante).all()
            for edge in edges:
                try:
                    # find how many times term occurs in article
                    edge.occurs_in = len(re.findall(edge.cons.searchpattern, txt))
                    print "<%s, %s> = %d" % (ante.label, edge.cons.label, edge.occurs_in)
                except:
Exemplo n.º 5
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Usage:
python graph/graph.py <PATH TO CONFIG.INI> <TYPE>
type: ii | it | tt
"""

from scripts.environment import load

if __name__ == "__main__":
    import sys
    load(sys.argv[-2])

    from scripts.model import *
    from mako.template import Template

    type = sys.argv[-1]
    if type == "ii":
        edges = model.meta.Session.query(model.IdeaGraphEdge).all()
    elif type == "it":
        edges = model.meta.Session.query(model.IdeaThinkerGraphEdge).all()
    elif type == "tt":
        edges = model.meta.Session.query(model.ThinkerGraphEdge).all()
    else:
        raise Exception("unrecognized type")

    graph = Template(filename='graph/graph.txt',
                     default_filters=['decode.utf8'])
    print graph.render_unicode(graph=edges).encode('utf-8', 'replace')
Exemplo n.º 6
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from scripts.environment import load

if __name__ == "__main__":
    import sys
    load(sys.argv[-1])

    from scripts.model import *
    from mako.template import Template

    node_q = model.meta.Session.query(model.Node)
    thinker_q = model.meta.Session.query(model.Thinker)
    profession_q = model.meta.Session.query(model.Profession)
    nationality_q = model.meta.Session.query(model.Nationality)

    nodes = node_q.all()
    thinkers = thinker_q.all()
    professions = profession_q.all()
    nationalities = nationality_q.all()

    owl = Template(filename='/Users/inpho/api/scripts/owl/owl.xml',
                   default_filters=['decode.utf8', 'u', 'x'])
    print owl.render_unicode(nodes=nodes,
                             thinkers=thinkers,
                             professions=professions,
                             nationalities=nationalities).encode(
                                 'utf-8', 'replace')

else: