示例#1
0
# scan_test.py
# Author: Thomas MINIER - MIT License 2017-2018
from query_engine.sage_engine import SageEngine
from query_engine.iterators.scan import ScanIterator
from database.hdt_file_connector import HDTFileConnector

hdtDoc = HDTFileConnector('tests/data/test.hdt')
engine = SageEngine()
triple = {
    'subject': '?s',
    'predicate': '?p',
    'object': '?o',
    'graph': 'watdiv100'
}


def test_scan_read():
    iterator, card = hdtDoc.search_triples(triple['subject'],
                                           triple['predicate'],
                                           triple['object'])
    scan = ScanIterator(iterator, triple, card)
    (results, saved, done) = engine.execute(scan, 10e7)
    assert len(results) == card
    assert done


def test_scan_save_nointerrupt():
    iterator, card = hdtDoc.search_triples(triple['subject'],
                                           triple['predicate'],
                                           triple['object'])
    scan = ScanIterator(iterator, triple, card)
示例#2
0
# filter_iterator_test.py
# Author: Thomas MINIER - MIT License 2017-2018
from query_engine.sage_engine import SageEngine
from query_engine.iterators.scan import ScanIterator
from query_engine.iterators.filter import FilterIterator
from query_engine.iterators.projection import ProjectionIterator
from query_engine.iterators.loader import load
from database.hdt_file_connector import HDTFileConnector
from tests.utils import DummyDataset
import math


hdtDoc = HDTFileConnector('tests/data/watdiv.10M.hdt')
engine = SageEngine()
triple = {
    'subject': 'http://db.uwaterloo.ca/~galuc/wsdbm/Offer1000',
    'predicate': '?p',
    'object': '?o',
    'graph': 'watdiv100'
}


def test_simple_filter_iterator():
    expression = "?p = <http://schema.org/eligibleRegion>"
    iterator, card = hdtDoc.search_triples(triple['subject'], triple['predicate'], triple['object'])
    scan = ProjectionIterator(ScanIterator(iterator, triple, card))
    iterator = FilterIterator(scan, expression)
    (results, saved, done) = engine.execute(iterator, math.inf)
    assert len(results) == 4
    for b in results:
        assert b['?p'] == 'http://schema.org/eligibleRegion'