示例#1
0
 def __init__(self, data=os.path.join(MODULE, "commonsense.csv"), **kwargs):
     """ A semantic network of commonsense, using different relation types:
         - is-a,
         - is-part-of,
         - is-opposite-of,
         - is-property-of,
         - is-related-to,
         - is-same-as,
         - is-effect-of.
     """
     Graph.__init__(self, **kwargs)
     self._properties = None
     # Load data from the given path,
     # a CSV-file of (concept1, relation, concept2, context, weight)-items.
     if data is not None:
         s = open(data).read()
         s = s.strip(BOM_UTF8)
         s = s.decode("utf-8")
         s = ((v.strip("\"") for v in r.split(",")) for r in s.splitlines())
         for concept1, relation, concept2, context, weight in s:
             self.add_edge(concept1,
                           concept2,
                           type=relation,
                           context=context,
                           weight=min(int(weight) * 0.1, 1.0))
示例#2
0
 def __init__(self, data=os.path.join(MODULE, "commonsense.csv"), **kwargs):
     """ A semantic network of commonsense, using different relation types:
         - is-a,
         - is-part-of,
         - is-opposite-of,
         - is-property-of,
         - is-related-to,
         - is-same-as,
         - is-effect-of.
     """
     Graph.__init__(self, **kwargs)
     self._properties = None
     # Load data from the given path,
     # a CSV-file of (concept1, relation, concept2, context, weight)-items.
     if data is not None:
         s = open(data).read()
         s = s.strip(BOM_UTF8)
         s = s.decode("utf-8")
         s = ((v.strip("\"") for v in r.split(",")) for r in s.splitlines())
         for concept1, relation, concept2, context, weight in s:
             self.add_edge(concept1, concept2, 
                 type = relation, 
              context = context, 
               weight = min(int(weight)*0.1, 1.0))
示例#3
0
 def remove(self, x):
     self._properties = None
     Graph.remove(self, x)
示例#4
0
 def add_edge(self, id1, id2, *args, **kwargs):
     """ Returns a Relation between two concepts (Edge subclass).
     """
     self._properties = None
     kwargs.setdefault("base", Relation)
     return Graph.add_edge(self, id1, id2, *args, **kwargs)
示例#5
0
 def add_node(self, id, *args, **kwargs):
     """ Returns a Concept (Node subclass).
     """
     self._properties = None
     kwargs.setdefault("base", Concept)
     return Graph.add_node(self, id, *args, **kwargs)
示例#6
0
 def remove(self, x):
     self._properties = None
     Graph.remove(self, x)
示例#7
0
 def add_edge(self, id1, id2, *args, **kwargs):
     """ Returns a Relation between two concepts (Edge subclass).
     """
     self._properties = None
     kwargs.setdefault("base", Relation)
     return Graph.add_edge(self, id1, id2, *args, **kwargs)
示例#8
0
 def add_node(self, id, *args, **kwargs):
     """ Returns a Concept (Node subclass).
     """
     self._properties = None
     kwargs.setdefault("base", Concept)
     return Graph.add_node(self, id, *args, **kwargs)
示例#9
0
from math import sin
from __init__ import Graph, MeshLinePlot
graph = Graph(xlabel='X',
              ylabel='Y',
              x_ticks_minor=5,
              x_ticks_major=25,
              y_ticks_major=1,
              y_grid_label=True,
              x_grid_label=True,
              padding=5,
              x_grid=True,
              y_grid=True,
              xmin=-0,
              xmax=100,
              ymin=-1,
              ymax=1)
plot = MeshLinePlot(color=[1, 0, 0, 1])
plot.points = [(x, sin(x / 10.)) for x in range(0, 101)]
graph.add_plot(plot)
while True:
    pass