home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / var / lib / python-support / python2.6 / rdflib / term_utils.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2009-04-20  |  5.5 KB  |  196 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. from rdflib import *
  5. from rdflib.Graph import QuotedGraph, Graph, ConjunctiveGraph, BackwardCompatGraph
  6.  
  7. def normalizeGraph(graph):
  8.     if isinstance(graph, QuotedGraph):
  9.         return (graph.identifier, 'F')
  10.     return (graph.identifier, term2Letter(graph.identifier))
  11.  
  12. TERM_INSTANCIATION_DICT = {
  13.     'U': URIRef,
  14.     'B': BNode,
  15.     'V': Variable,
  16.     'L': Literal }
  17. GRAPH_TERM_DICT = {
  18.     'F': (QuotedGraph, URIRef),
  19.     'U': (Graph, URIRef),
  20.     'B': (Graph, BNode) }
  21.  
  22. def term2Letter(term):
  23.     if isinstance(term, URIRef):
  24.         return 'U'
  25.     if isinstance(term, BNode):
  26.         return 'B'
  27.     if isinstance(term, Literal):
  28.         return 'L'
  29.     if isinstance(term, QuotedGraph):
  30.         return 'F'
  31.     if isinstance(term, Variable):
  32.         return 'V'
  33.     if isinstance(term, Graph):
  34.         return term2Letter(term.identifier)
  35.     if term is None:
  36.         return 'L'
  37.     raise Exception('The given term (%s) is not an instance of any of the known types (URIRef,BNode,Literal,QuotedGraph, or Variable).  It is a %s' % (term, type(term)))
  38.  
  39.  
  40. def constructGraph(term):
  41.     return GRAPH_TERM_DICT[term]
  42.  
  43.  
  44. def triplePattern2termCombinations(.0):
  45.     (s, p, o) = .0
  46.     combinations = []
  47.     if isinstance(o, Literal):
  48.         for key, val in TERM_COMBINATIONS.items():
  49.             if key[OBJECT] == 'O':
  50.                 combinations.append(val)
  51.                 continue
  52.         
  53.     
  54.     return combinations
  55.  
  56.  
  57. def type2TermCombination(member, klass, context):
  58.     
  59.     try:
  60.         rt = TERM_COMBINATIONS['%sU%s%s' % (term2Letter(member), term2Letter(klass), normalizeGraph(context)[-1])]
  61.         return rt
  62.     except:
  63.         raise Exception('Unable to persist classification triple: %s %s %s' % (member, 'rdf:type', klass, context))
  64.  
  65.  
  66.  
  67. def statement2TermCombination(subject, predicate, obj, context):
  68.     return TERM_COMBINATIONS['%s%s%s%s' % (term2Letter(subject), term2Letter(predicate), term2Letter(obj), normalizeGraph(context)[-1])]
  69.  
  70. SUBJECT = 0
  71. PREDICATE = 1
  72. OBJECT = 2
  73. CONTEXT = 3
  74. TERM_COMBINATIONS = {
  75.     'UUUU': 0,
  76.     'UUUB': 1,
  77.     'UUUF': 2,
  78.     'UUVU': 3,
  79.     'UUVB': 4,
  80.     'UUVF': 5,
  81.     'UUBU': 6,
  82.     'UUBB': 7,
  83.     'UUBF': 8,
  84.     'UULU': 9,
  85.     'UULB': 10,
  86.     'UULF': 11,
  87.     'UUFU': 12,
  88.     'UUFB': 13,
  89.     'UUFF': 14,
  90.     'UVUU': 15,
  91.     'UVUB': 16,
  92.     'UVUF': 17,
  93.     'UVVU': 18,
  94.     'UVVB': 19,
  95.     'UVVF': 20,
  96.     'UVBU': 21,
  97.     'UVBB': 22,
  98.     'UVBF': 23,
  99.     'UVLU': 24,
  100.     'UVLB': 25,
  101.     'UVLF': 26,
  102.     'UVFU': 27,
  103.     'UVFB': 28,
  104.     'UVFF': 29,
  105.     'VUUU': 30,
  106.     'VUUB': 31,
  107.     'VUUF': 33,
  108.     'VUVU': 34,
  109.     'VUVB': 35,
  110.     'VUVF': 36,
  111.     'VUBU': 37,
  112.     'VUBB': 38,
  113.     'VUBF': 39,
  114.     'VULU': 40,
  115.     'VULB': 41,
  116.     'VULF': 42,
  117.     'VUFU': 43,
  118.     'VUFB': 44,
  119.     'VUFF': 45,
  120.     'VVUU': 46,
  121.     'VVUB': 47,
  122.     'VVUF': 48,
  123.     'VVVU': 49,
  124.     'VVVB': 50,
  125.     'VVVF': 51,
  126.     'VVBU': 52,
  127.     'VVBB': 53,
  128.     'VVBF': 54,
  129.     'VVLU': 55,
  130.     'VVLB': 56,
  131.     'VVLF': 57,
  132.     'VVFU': 58,
  133.     'VVFB': 59,
  134.     'VVFF': 60,
  135.     'BUUU': 61,
  136.     'BUUB': 62,
  137.     'BUUF': 63,
  138.     'BUVU': 64,
  139.     'BUVB': 65,
  140.     'BUVF': 66,
  141.     'BUBU': 67,
  142.     'BUBB': 68,
  143.     'BUBF': 69,
  144.     'BULU': 70,
  145.     'BULB': 71,
  146.     'BULF': 72,
  147.     'BUFU': 73,
  148.     'BUFB': 74,
  149.     'BUFF': 75,
  150.     'BVUU': 76,
  151.     'BVUB': 77,
  152.     'BVUF': 78,
  153.     'BVVU': 79,
  154.     'BVVB': 80,
  155.     'BVVF': 81,
  156.     'BVBU': 82,
  157.     'BVBB': 83,
  158.     'BVBF': 84,
  159.     'BVLU': 85,
  160.     'BVLB': 86,
  161.     'BVLF': 87,
  162.     'BVFU': 88,
  163.     'BVFB': 89,
  164.     'BVFF': 90,
  165.     'FUUU': 91,
  166.     'FUUB': 92,
  167.     'FUUF': 93,
  168.     'FUVU': 94,
  169.     'FUVB': 95,
  170.     'FUVF': 96,
  171.     'FUBU': 97,
  172.     'FUBB': 98,
  173.     'FUBF': 99,
  174.     'FULU': 100,
  175.     'FULB': 101,
  176.     'FULF': 102,
  177.     'FUFU': 103,
  178.     'FUFB': 104,
  179.     'FUFF': 105,
  180.     'FVUU': 106,
  181.     'FVUB': 107,
  182.     'FVUF': 108,
  183.     'FVVU': 109,
  184.     'FVVB': 110,
  185.     'FVVF': 111,
  186.     'FVBU': 112,
  187.     'FVBB': 113,
  188.     'FVBF': 114,
  189.     'FVLU': 115,
  190.     'FVLB': 116,
  191.     'FVLF': 117,
  192.     'FVFU': 118,
  193.     'FVFB': 119,
  194.     'FVFF': 120 }
  195. REVERSE_TERM_COMBINATIONS = []([ (value, key) for key, value in TERM_COMBINATIONS.items() ])
  196.