Skip to content
Browse files

trying to get prolog engine working again after nodecentric.

  • Loading branch information...
1 parent c04d9ce commit 24606ba1197cf1c61e652481430a63a9a6a94fb6 @sandhawke committed
Showing with 28 additions and 41 deletions.
  1. +2 −22 plugins/do_import.py
  2. +3 −2 plugins/func_to_pred.py
  3. +18 −14 plugins/prolog_out.py
  4. +5 −3 query.py
View
24 plugins/do_import.py
@@ -7,6 +7,8 @@
include the necessary additional rulesets?
+ -- ONLY does rdf-profile imports of TURTLE documents (dumb)
+ -- Should factor out the RDF-to-Frames and Merge bits.
"""
@@ -138,28 +140,6 @@ def list_readings(self, node):
for rest2 in self.list_readings(rest):
yield (first,) + rest2
-tests = [
- # these are the ImportsSupport tests
- "IRI_from_RDF_Literal",
- "RDF_Combination_Blank_Node",
- "RDF_Combination_Constant_Equivalence_1",
- "RDF_Combination_Constant_Equivalence_2",
- "RDF_Combination_Constant_Equivalence_3",
- "RDF_Combination_Constant_Equivalence_4",
- "RDF_Combination_Constant_Equivalence_Graph_Entailment",
- "RDF_Combination_Invalid_Constant_1",
- "RDF_Combination_Invalid_Constant_2",
- "RDF_Combination_Member_1",
- "RDF_Combination_SubClass",
- "RDF_Combination_SubClass_2",
- "RDF_Combination_SubClass_3",
- "RDF_Combination_SubClass_4",
- "RDF_Combination_SubClass_5",
- "RDF_Combination_SubClass_6",
- "YoungParentDiscount_1",
- "YoungParentDiscount_2",
- ]
-
class SysTestPlugin (plugin.Plugin):
""
View
5 plugins/func_to_pred.py
@@ -42,7 +42,7 @@ def transform(self, instance):
return instance
def replace_atomic(self, atom):
- '''Replace any atoms containing external-exprs with with an And
+ '''Replace any atoms containing external-exprs with an And
of the atom re-written and a call to calc'''
if not (atom.has_type(rifns+"Atom") or
@@ -60,6 +60,7 @@ def replace_atomic(self, atom):
setattr(calc, rifns+"op", self.calc_pred)
setattr(calc, rifns+"args", self.factory.Sequence(items=[var, expr]))
setattr(parent, rifns+"formula", calc)
+ getattr(parent, rifns+"formula").clear()
setattr(parent, rifns+"formula", atom)
debug('f2p)', 'replaced it')
return parent
@@ -80,7 +81,7 @@ def replace_external(self, external, harvest):
# TODO: put the variable name up in quantifier!!! (and make sure
# it's unique...)
# (we'll have to do that with a trick like 'harvest' on Forall, I guess)
- setattr(var, rifns+"name", self.factory.string("genvar%d" % self.v_count))
+ setattr(var, rifns+"name", self.factory.StringValue("genvar%d" % self.v_count))
self.v_count += 1
harvest.append( (var, getattr(external, rifns+"content").the) )
debug('f2p(', 'found an external; replaced with', var)
View
32 plugins/prolog_out.py
@@ -11,8 +11,6 @@
"""
import sys
-import serializer2
-import plugin
from cStringIO import StringIO
import re
import tempfile
@@ -21,6 +19,10 @@
from debugtools import debug
import qname
+import nodecentric
+import datanode
+import nodewriter
+import plugin
import xml_in
import escape
import query
@@ -57,10 +59,10 @@ def atom_unquote(s):
s = s.replace("\\\\", "\\")
return s
-class Serializer(serializer2.General):
+class Serializer(nodewriter.General):
def __init__(self, supress_nsmap=False, **kwargs):
- serializer2.General.__init__(self, **kwargs)
+ nodewriter.General.__init__(self, **kwargs)
self.assertional = True
self.metadata = []
self.if_keep = ""
@@ -76,10 +78,10 @@ def __init__(self, supress_nsmap=False, **kwargs):
def default_do(self, obj):
- if isinstance(obj, AST2.Instance):
+ if isinstance(obj, nodecentric.Instance):
error.notify(error.NotImplemented("Not Implemented: "
- +obj.primary_type))
- self.out("not_implemented('%s')" % obj.primary_type)
+ +obj.rdf_type.any.as_string))
+ self.out("not_implemented('%s')" % obj.rdf_type.any.as_string)
else:
error.notify(error.NotImplemented("Not Implemented (obj): "+
str(type(obj))))
@@ -133,7 +135,7 @@ def irimap(self):
self.out('\n% This namespace table isnt actually used yet.')
# self.out(':- discontiguous(ns/2).')
for short in self.nsmap.shortNames():
- self.out('ns('+short+', '+atom_quote(self.nsmap.getLong(short)), ").")
+ self.out('ns('+atom_quote(short)+', '+atom_quote(self.nsmap.getLong(short)), ").")
self.out('\n')
def local(self, text):
@@ -233,7 +235,7 @@ def do_Implies(self, obj):
self.assertional = was_assertional
def do_And(self, obj):
- values = obj.formula.values
+ values = obj.rif_formula.values_list
if len(values) == 0:
self.outk('fail')
elif len(values) == 1:
@@ -264,7 +266,7 @@ def do_Atom(self, obj):
self.do(obj.op.the)
# surprisingly, the <args> is optional in the XML Schema
- if obj.args.values:
+ if obj.args.values_list:
self.outk("(")
self.do(obj.args.the)
self.outk(")")
@@ -411,7 +413,7 @@ def __init__(self, **kwargs):
self.ser = Serializer(**kwargs)
def serialize(self, doc, output_stream):
- AST2.default_namespace = rifns
+ # nodecentric.default_namespace = rifns
self.ser.stream = output_stream
self.ser.do(doc)
@@ -449,11 +451,12 @@ def run_query(kb, query, msg):
nsmap = qname.Map()
nsmap.defaults = [qname.common]
+ nsmap.bind("", "http://www.w3.org/2007/rif#")
to_pl.write("% "+msg)
- rifeval = AST2.Instance('Const',
- value=AST2.DataValue(rif_bip+'eval',
- rifns+'iri'))
+ ast = datanode.NodeFactory()
+ rifeval = ast.Instance('rif_Const')
+ rifeval.rif_value = ast.DataValue(rif_bip+'eval', rifns+'iri')
kb_pform = func_to_pred.Plugin(calc_pred=rifeval,factory=kb.factory).transform(kb)
query_pform = func_to_pred.Plugin(calc_pred=rifeval).transform(query)
Plugin(nsmap=nsmap, supress_nsmap=True).serialize(kb_pform, to_pl)
@@ -521,6 +524,7 @@ def test2():
n+=1
pattern = query.from_conclusion(conc)
+ #prem.factory.nsmap.bind("", "http://www.w3.org/2007/rif#")
try:
result = run_query(prem, pattern, msg="From test "+test)
except error.Error, e:
View
8 query.py
@@ -5,14 +5,16 @@
"""
-import AST2
+import datanode
def from_conclusion(node):
"""Turn a test-case conclusion into a proper Query,
with no variables.
"""
- q = AST2.Instance("Query")
- q.variables = AST2.Sequence()
+ ast = datanode.NodeFactory()
+ ast.nsmap.bind("", "http://www.w3.org/2007/rif#")
+ q = ast.Instance("Query")
+ q.variables = ast.Sequence()
q.pattern = node
return q

0 comments on commit 24606ba

Please sign in to comment.
Something went wrong with that request. Please try again.