Ejemplo n.º 1
0
# that displays the graph using an interactive, force-based spring layout.
# You can drag the nodes around - open index.html in a browser and try it out!
# The layout can be tweaked in many ways:

export(
    g,
    "test",
    overwrite=True,  # Overwrite existing folder?
    width=700,  # <canvas> width.
    height=500,  # <canvas> height.
    frames=500,  # Number of frames of animation.
    fps=20,  # Nubmer of frames per second.
    weight=[WEIGHT, CENTRALITY
            ],  # Calculate eigenvector & betweenness centrality (in Python).
    weighted=0.5,  # Indicate nodes with a higher centrality with a shadow?
    directed=True,  # Indicate connection direction with an arrow?
    distance=10,  # Overall connection length.
    k=4.0,  # Force constant.
    force=0.01,  # Force dampener.
    repulsion=50,  # Repulsive force radius.
    prune=0,  # Remove nodes that have <= connections? (in Javascript)
    pack=
    True,  # Keep clusters close together + visualize node weight as node radius?
    stylesheet=
    "default",  # INLINE, DEFAULT, None, or the path to your own stylesheet.
    javascript="js/",
    href={"1":
          "http://www.clips.ua.ac.be/pages/pattern-graph"},  # Node.id => URL
    css={"1": "node-link-docs"}  # Node.id => CSS class.
)
Ejemplo n.º 2
0
for i in range(1,10):
    # Set cached=False for live results:
    for result in Twitter(language="en").search("\"is the new\"", start=i, count=100, cached=True):
        s = result.text
        s = s.replace("\n", " ")
        s = s.lower()
        s = s.replace("is the new", "NEW")
        s = s.split(" ")
        try:
            i = s.index("NEW")
            A = s[i-1].strip("?!.:;,#@\"'")
            B = s[i+1].strip("?!.:;,#@\"'")
            # Exclude common phrases such as "this is the new thing".
            if A and B and A not in ("it", "this", "here", "what", "why", "where"):
                comparisons.append((A,B))
        except:
            pass

g = Graph()
for A, B in comparisons:
    e = g.add_edge(B, A) # "A is the new B": A <= B
    e.weight += 0.1
    print B, "=>", A

# Not all nodes will be connected, there will be multiple subgraphs.
# Simply take the largest subgraph for our visualization.
g = g.split()[0]

export(g, "trends", weight=True, weighted=True, directed=True, overwrite=True)
Ejemplo n.º 3
0
for i in range(1,10):
    # Set cached=False for live results:
    for result in Twitter(language="en").search("\"is the new\"", start=i, count=100, cached=True):
        s = result.description
        s = s.replace("\n", " ")
        s = s.lower()
        s = s.replace("is the new", "NEW")
        s = s.split(" ")
        try:
            i = s.index("NEW")
            A = s[i-1].strip("?!.:;,#@\"'")
            B = s[i+1].strip("?!.:;,#@\"'")
            # Exclude common phrases such as "this is the new thing".
            if A and B and A not in ("it", "this", "here", "what", "why", "where"):
                comparisons.append((A,B))
        except:
            pass

g = Graph()
for A, B in comparisons:
    e = g.add_edge(B, A) # "A is the new B": A <= B
    e.weight += 0.1
    print B, "=>", A

# Not all nodes will be connected, there will be multiple subgraphs.
# Simply take the largest subgraph for our visualization.
g = g.split()[0]

export(g, "trends", weight=True, weighted=True, directed=True, overwrite=True)
Ejemplo n.º 4
0
# This node's label is different from its id.
# We'll also make it a link, see the href attribute at the bottom.
g["1"].text.string = "home"

# The export() command generates a folder with an index.html,
# that displays the graph using an interactive, force-based spring layout.
# You can drag the nodes around - open index.html in a browser and try it out!
# The layout can be tweaked in many ways:

export(g, "test", 
    overwrite = True,      # Overwrite existing folder?
        width = 700,       # <canvas> width.
       height = 500,       # <canvas> height.
       frames = 500,       # Number of frames of animation.
          fps = 20,        # Nubmer of frames per second.
       weight = [WEIGHT, CENTRALITY], # Calculate eigenvector & betweenness centrality (in Python).
     weighted = 0.5,       # Indicate nodes with a higher centrality with a shadow?
     directed = True,      # Indicate connection direction with an arrow?
     distance = 10,        # Overall connection length.
            k = 4.0,       # Force constant.
        force = 0.01,      # Force dampener.
    repulsion = 50,        # Repulsive force radius.
        prune = 0,         # Remove nodes that have <= connections? (in Javascript)
         pack = True,      # Keep clusters close together + visualize node weight as node radius?
   stylesheet = "default", # INLINE, DEFAULT, None, or the path to your own stylesheet.
   javascript = "js/",
         href = {"1": "http://www.clips.ua.ac.be/pages/pattern-graph"}, # Node.id => URL
          css = {"1": "node-link-docs"} # Node.id => CSS class.
)
Ejemplo n.º 5
0
 def display(self, name='default'):
     from pattern.graph import Graph, export
     graph = Graph()
     self._display(self.root, graph)
     export(graph, name, directed=True, weight=0.6, distance=6)
            b = m.constituents(p[-1])[+0] # Right NP.
            a = (isinstance(a, Chunk) and a.head or a).string
            b = (isinstance(b, Chunk) and b.head or b).string
            if a and b:
                if a not in g:
                    g.add_node(a, radius=5, stroke=(0,0,0,0.8))
                if b not in g:
                    g.add_node(b, radius=5, stroke=(0,0,0,0.8))
                g.add_edge(g[b], g[a], stroke=(0,0,0,0.6))

g = g.split()[0] # Largest subgraph.
 
for n in g.sorted()[:40]: # Sorted by Node.weight.
    n.fill = (0.0, 0.5, 1.0, 0.7 * n.weight)

export(g, 'test', directed=True, weighted=0.6, distance=6, force=0.05, repulsion=150)
import os
os.system('ls -lR test/')


# Example of pattern: http://www.clips.ua.ac.be/pages/pattern

from pattern.web    import Bing, plaintext
from pattern.en     import Sentence, Chunk, parse
from pattern.search import Pattern
from pattern.graph  import Graph, Node, Edge, export
 
g = Graph()
for i in range(1):
    print "--------------", i
    for r in Bing().search('"more important than"', start=i+1, count=50):
            if a and b:
                if a not in g:
                    g.add_node(a, radius=5, stroke=(0, 0, 0, 0.8))
                if b not in g:
                    g.add_node(b, radius=5, stroke=(0, 0, 0, 0.8))
                g.add_edge(g[b], g[a], stroke=(0, 0, 0, 0.6))

g = g.split()[0]  # Largest subgraph.

for n in g.sorted()[:40]:  # Sorted by Node.weight.
    n.fill = (0.0, 0.5, 1.0, 0.7 * n.weight)

export(g,
       'test',
       directed=True,
       weighted=0.6,
       distance=6,
       force=0.05,
       repulsion=150)
import os
os.system('ls -lR test/')

# Example of pattern: http://www.clips.ua.ac.be/pages/pattern

from pattern.web import Bing, plaintext
from pattern.en import Sentence, Chunk, parse
from pattern.search import Pattern
from pattern.graph import Graph, Node, Edge, export

g = Graph()
for i in range(1):