コード例 #1
0
def test_assertion():
    # fresh start
    Dataset.drop_collection()
    Assertion.drop_collection()
    
    #create test dataset
    dataset = Dataset.create(language = 'en', name = '/data/test')

    #make a test assertion
    a1 = Assertion.make('/data/test',"/rel/IsA",["/concept/test/assertion", "/concept/test/test"])
    e = Expression.make(a1, "{0} is a {1}", ['this assertion', 'test'], 'en')
    print e.assertion
    e.add_support([dataset.get_root_reason()])
    a1.add_support([dataset.get_root_reason()])
    a1.save()
    a1.make_generalizations('/data/test/root')
    a2 = Assertion.objects.get(
        dataset='/data/test',
        relation='/rel/IsA',
        argstr="/concept/test/assertion,/concept/test/test"
    )
    print a1.get_expressions()
    assert a2.get_expressions()[0].text == 'this assertion is a test'

    a3 = Assertion.objects.get(
        dataset='/data/test',
        relation='/rel/IsA',
        argstr="/concept/test/assertion,*"
    )
    assert a3.get_expressions()[0].text == 'this assertion is a {1}'
    
    a4 = Assertion.objects.get(
        dataset='/data/test',
        relation='/rel/IsA',
        argstr="*,/concept/test/test"
    )
    assert a4.get_expressions()[0].text == '{0} is a test'
    
    a5 = Assertion.objects.get(
        dataset='/data/test',
        relation='/rel/IsA',
        argstr="*,*"
    )
    assert a5.get_expressions()[0].text == '{0} is a {1}'
    
    #clean up
    Dataset.drop_collection()
    Assertion.drop_collection()
コード例 #2
0
ファイル: test_generalize.py プロジェクト: vipmath/conceptdb
def test_assertion():
    # fresh start
    Dataset.drop_collection()
    Assertion.drop_collection()

    #create test dataset
    dataset = Dataset.create(language='en', name='/data/test')

    #make a test assertion
    a1 = Assertion.make('/data/test', "/rel/IsA",
                        ["/concept/test/assertion", "/concept/test/test"])
    e = Expression.make(a1, "{0} is a {1}", ['this assertion', 'test'], 'en')
    print e.assertion
    e.add_support([dataset.get_root_reason()])
    a1.add_support([dataset.get_root_reason()])
    a1.save()
    a1.make_generalizations('/data/test/root')
    a2 = Assertion.objects.get(
        dataset='/data/test',
        relation='/rel/IsA',
        argstr="/concept/test/assertion,/concept/test/test")
    print a1.get_expressions()
    assert a2.get_expressions()[0].text == 'this assertion is a test'

    a3 = Assertion.objects.get(dataset='/data/test',
                               relation='/rel/IsA',
                               argstr="/concept/test/assertion,*")
    assert a3.get_expressions()[0].text == 'this assertion is a {1}'

    a4 = Assertion.objects.get(dataset='/data/test',
                               relation='/rel/IsA',
                               argstr="*,/concept/test/test")
    assert a4.get_expressions()[0].text == '{0} is a test'

    a5 = Assertion.objects.get(dataset='/data/test',
                               relation='/rel/IsA',
                               argstr="*,*")
    assert a5.get_expressions()[0].text == '{0} is a {1}'

    #clean up
    Dataset.drop_collection()
    Assertion.drop_collection()
コード例 #3
0
ファイル: handlers.py プロジェクト: vipmath/conceptdb
    def assertionExpressionLookup(self, request, obj_url):
        assertionID = request.GET['id']
        start = int(request.GET.get('start', '0'))
        limit = int(request.GET.get('limit', '10'))

        #NOTE: should return ranked by confidence score.  For now assume that they do.
        try:
            assertion = Assertion.get(assertionID)
        except DoesNotExist:
            return rc.NOT_FOUND
        cursor = Expression.objects(assertion=assertion)[start:start + limit]
        expressions = []
        while (True):
            try:
                expressions.append(str(cursor.next().id))
            except StopIteration:
                break  #no more assertions within the skip/limit boundaries

        if len(expressions) == 0:  #no assertions were found for the concept
            return rc.NOT_FOUND

        return "{expressions: " + str(expressions) + "}"
コード例 #4
0
ファイル: handlers.py プロジェクト: Web5design/conceptdb
    def assertionExpressionLookup(self, request, obj_url):
        assertionID = request.GET['id']
        start = int(request.GET.get('start', '0'))
        limit = int(request.GET.get('limit', '10'))

        #NOTE: should return ranked by confidence score.  For now assume that they do.
        try:
            assertion = Assertion.get(assertionID)
        except DoesNotExist:
            return rc.NOT_FOUND
        cursor = Expression.objects(assertion = assertion)[start:start + limit]
        expressions = []
        while (True):
            try:
                expressions.append(str(cursor.next().id))
            except StopIteration:
                break #no more assertions within the skip/limit boundaries

        if len(expressions) == 0: #no assertions were found for the concept
            return rc.NOT_FOUND

        return "{expressions: " + str(expressions) + "}"
コード例 #5
0
def test_expression():

    #start clean
    Expression.drop_collection()
    Assertion.drop_collection()

    a1 = Assertion.make('/data/test', '/rel/IsA',
                        ['/concept/test/assertion', '/concept/test/test'])

    expr = Expression.make(a1, '{0} is a {1}', ['this assertion', 'test'],
                           'en')

    #check for consistency, ensure all attributes are readable
    expr.check_consistency()
    expr.assertion
    expr.text
    expr.confidence
    expr.arguments
    expr.language
    expr.frame
    expr.id

    assert expr.name == '/expression/%s' % expr.id

    # load the same assertion from the DB
    a2 = Assertion.make('/data/test', '/rel/IsA',
                        ['/concept/test/assertion', '/concept/test/test'])
    assert expr.assertion == a2

    #test static methods
    replace = Expression.replace_args(expr.frame, expr.arguments)
    assert replace == "this assertion is a test"

    #clean up
    Assertion.drop_collection()
    Expression.drop_collection()
コード例 #6
0
def test_expression():

    #start clean
    Expression.drop_collection()
    Assertion.drop_collection() 
    
    a1 = Assertion.make('/data/test','/rel/IsA',
                        ['/concept/test/assertion', '/concept/test/test'])
   
    expr = Expression.make(a1, '{0} is a {1}', ['this assertion', 'test'], 'en')
    
    #check for consistency, ensure all attributes are readable
    expr.check_consistency()
    expr.assertion
    expr.text
    expr.confidence
    expr.arguments
    expr.language
    expr.frame
    expr.id

    assert expr.name == '/expression/%s' % expr.id

    # load the same assertion from the DB
    a2 = Assertion.make('/data/test','/rel/IsA',
                        ['/concept/test/assertion', '/concept/test/test'])
    assert expr.assertion == a2


    #test static methods
    replace = Expression.replace_args(expr.frame, expr.arguments)
    assert replace == "this assertion is a test"

    #clean up
    Assertion.drop_collection() 
    Expression.drop_collection()
コード例 #7
0
ファイル: handlers.py プロジェクト: Web5design/conceptdb
 def expressionLookup(self, obj_url):
     try:
         return Expression.get(obj_url.replace('/expression/', ''))
     except DoesNotExist:
         return rc.NOT_FOUND
コード例 #8
0
import conceptdb
from conceptdb.assertion import Assertion, Expression, Sentence
from conceptdb.metadata import Dataset
from conceptdb.justify import ReasonConjunction

conceptdb.connect_to_mongodb('test')

#clean out whatever was in test before
Assertion.drop_collection()
Dataset.drop_collection()
Expression.drop_collection()
ReasonConjunction.drop_collection()
Sentence.drop_collection()

#make a new dataset
d = Dataset.make('/data/test', 'en')

#make a couple of assertions
a1 = Assertion.make(d, '/rel/IsA', ['/concept/assertion', '/concept/test'])
a2 = Assertion.make(d, '/rel/IsA', ['/concept/database', '/concept/test'])

#add expressions to them
e1 = a1.make_expression('{0} is a {1}', a1.arguments, d.language)
e2 = a2.make_expression('{0} is a {1}', a2.arguments, d.language)

#connect them to sentences
a1.connect_to_sentence(d, 'This assertion is a test.')
a2.connect_to_sentence(d, 'This database is a test.')

#make a reason for myself
r = ReasonConjunction.make('/data/test/contributor/elhawk', ['user_factor'], 0.75, True)
コード例 #9
0
import conceptdb
from conceptdb.assertion import Assertion, Expression, Sentence
from conceptdb.metadata import Dataset
from conceptdb.justify import ReasonConjunction

conceptdb.connect_to_mongodb('test')

#clean out whatever was in test before
Assertion.drop_collection()
Dataset.drop_collection()
Expression.drop_collection()
ReasonConjunction.drop_collection()
Sentence.drop_collection()

#make a new dataset
d = Dataset.make('/data/test', 'en')

#make a couple of assertions
a1 = Assertion.make(d, '/rel/IsA', ['/concept/assertion', '/concept/test'])
a2 = Assertion.make(d, '/rel/IsA', ['/concept/database', '/concept/test'])

#add expressions to them
e1 = a1.make_expression('{0} is a {1}', a1.arguments, d.language)
e2 = a2.make_expression('{0} is a {1}', a2.arguments, d.language)

#connect them to sentences
a1.connect_to_sentence(d, 'This assertion is a test.')
a2.connect_to_sentence(d, 'This database is a test.')

#make a reason for myself
r = ReasonConjunction.make('/data/test/contributor/elhawk', ['user_factor'],
コード例 #10
0
ファイル: handlers.py プロジェクト: vipmath/conceptdb
 def expressionLookup(self, obj_url):
     try:
         return Expression.get(obj_url.replace('/expression/', ''))
     except DoesNotExist:
         return rc.NOT_FOUND