DgraphAndWeaviateTest

From BITPlan Wiki
Jump to navigation Jump to search

OsProject

OsProject
edit
id  DgraphAndWeaviateTest
state  
owner  Wolfgang Fahl
title  DgraphAndWeaviateTest
url  https://github.com/WolfgangFahl/DgraphAndWeaviateTest
version  0.0.1
description  
date  2020/08/05
since  
until  

This is sample project to test Python based access to Dgraph, Weaviate and Apache Jena

Installation and test

Prerequisites

  • python > version 3.6 - tested with version 3.6/3.7/3.8
  • docker e.g. docker desktop community - tested with e.g. docker desktop 2.3.0.4 Docker version 19.03.12
  • Operating system that can run bash scripts e.g. macports, linux - tested on Mac OS 10.13.6 Macports 2.6.2, Ubuntu 18.04 LTS

Installation

https://github.com/WolfgangFahl/DgraphAndWeaviateTest
cd DgraphAndWeaviateTest
scripts/install

Starting servers

see also DgraphAndWeaviateTest

# command to run Dgraph
# pull dgraph
scripts/dgraph -p
# run dgraph
scripts/dgraph
# pull and run weaviate
scripts/weaviate
# install apache jena and load example data
scripts/jena -l sampledata/example.ttl
# run apache jena fuseki server
scripts/jena -f example

Test

scripts/test

Dgraph Installation

docker based pull:

scripts/dgraph -p

Dgraph start

docker based start of

  • alpha
  • ratel
  • zero
scripts/dgraph

Dgraph stop

scripts/dgraph -k

scripts/dgraph usage

scripts/dgraph -h
scripts/dgraph [-b|--bash|-c|--clean|-h|--help|-k|--kill|-p|--pull]

-b | --bash: start a bash terminal shell within the currently running container
-h | --help: show this usage
-k | --kill: stop the docker image
-p | --pull: pull the docker image
-c | --clean: clean start with kill and purge of all data

Apache Jena

The jena -l and jena -f options will automatically download and unpack the needed Apache jena files.

Jena load example dataset

scripts/jena -l sampledata/example.ttl

Jena fuseki server start

scripts/jena -f example

You should be able to browse the admin GUI at http://localhost:3030 and have the example dataset ready for you

Jena fuseki server start

scripts/jena -k

jena script usage

scripts/jena -h
scripts/jena [-f|--fuseki|-h|--help|-k|--kill|-l|--load]

-f | --fuseki [dataset]: download and start fuseki server with the given dataset
-h | --help: show this usage
-k | --kill: kill the running fuseki server
-l | --load [ttl file]: download jena / tdbloader and load given ttl file

Example unit tests

Dgraph unit test

def testDgraph(self):
        ''' 
        test basic Dgraph operation
        '''
        dgraph=Dgraph(debug=True)
        # drop all data and schemas
        dgraph.drop_all()
        # create a schema for Pokemons
        schema='''
        name: string @index(exact) .
        weight: float .
        height: float .
type Pokemon {
   name
   weight
   height
}'''
        dgraph.addSchema(schema)
        # prepare a list of Pokemons to be added
        pokemonList=[{'name':'Pikachu', 'weight':  6, 'height': 0.4 },
                  {'name':'Arbok',   'weight': 65, 'height': 3.5 }, 
                  {'name':'Raichu',  'weight': 30, 'height': 0.8 }, 
                  {'name':'Sandan',  'weight': 12, 'height': 0.6 }]
        # add the list in a single transaction
        dgraph.addData(obj=pokemonList)
        # retrieve the data via GraphQL+ query
        graphQuery='''{
# list of pokemons
  pokemons(func: has(name), orderasc: name) {
    name
    weight
    height
  }
}'''
        queryResult=dgraph.query(graphQuery)
        # check the result
        self.assertTrue('pokemons' in queryResult)
        pokemons=queryResult['pokemons']
        self.assertEqual(len(pokemonList),len(pokemons))
        sortindex=[1,0,2,3]
        for index,pokemon in enumerate(pokemons):
            expected=pokemonList[sortindex[index]]
            self.assertEquals(expected,pokemon)
        # close the database connection
        dgraph.close()

Example test session

see https://travis-ci.org/github/WolfgangFahl/DgraphAndWeaviateTest/jobs/715131236