Both sides previous revision
Poprzednia wersja
Nowa wersja
|
Poprzednia wersja
|
pl:dydaktyka:ztb:2010:projekty:nosql_casandra:start [2010/06/30 00:08] ztb2010 |
pl:dydaktyka:ztb:2010:projekty:nosql_casandra:start [2019/06/27 15:50] (aktualna) |
make | make |
make install | make install |
| </code> |
| |
| do poprawnego działania z pythonem należy jeszcze ręcznie zainstalować biblioteki: |
| <code> |
| cd lib/py |
| python setup.py install |
</code> | </code> |
| |
pp = pprint.PrettyPrinter(indent = 2) | pp = pprint.PrettyPrinter(indent = 2) |
host = 'localhost' | host = 'localhost' |
port = 9090 | port = 9160 |
uri = '' | uri = '' |
framed = False | framed = False |
argi = 1 | argi = 1 |
| |
if sys.argv[argi] == '-h': | if len(sys.argv)>1 and sys.argv[argi] == '-h': |
parts = sys.argv[argi+1].split(':') | parts = sys.argv[argi+1].split(':') |
host = parts[0] | host = parts[0] |
port = int(parts[1]) | port = int(parts[1]) |
argi += 2 | argi += 2 |
| |
| |
if http: | if http: |
def translate(self, lang_from, word_from, lang_to): | def translate(self, lang_from, word_from, lang_to): |
colPath = ColumnPath("Words", lang_from, lang_to) | colPath = ColumnPath("Words", lang_from, lang_to) |
pp.pprint(client.get('Dictionary', word_from, colPath, ConsistencyLevel.ONE,)) | try: |
| ret = client.get('Dictionary', word_from, colPath, ConsistencyLevel.ONE,) |
| if ret: |
| print "translate " + word_from + " (" + lang_from + " - " +lang_to+"): " + ret.column.value |
| except NotFoundException: |
| print "there is no translate for " + word_from + " (" + lang_from + " - " +lang_to+")" |
def getAllTranslates(self, lang_from, word_from): | def getAllTranslates(self, lang_from, word_from): |
colParent = ColumnParent("Words", lang_from) | colParent = ColumnParent("Words", lang_from) |
slPred = SlicePredicate(None, SliceRange('','')) | slPred = SlicePredicate(None, SliceRange('','')) |
pp.pprint(client.get_slice('Dictionary', word_from, colParent, slPred, ConsistencyLevel.ONE,)) | ret = client.get_slice('Dictionary', word_from, colParent, slPred, ConsistencyLevel.ONE,) |
| print "all transalte for word " + word_from + " (" + lang_from + "):" |
| for item in ret: |
| print " translate " + word_from + " (" + lang_from + " - " +item.column.name+"): " + item.column.value |
| |
| |
colPath = ColumnPath("Words", lang_from, lang_to) | colPath = ColumnPath("Words", lang_from, lang_to) |
timestamp = int(time.time()) | timestamp = int(time.time()) |
pp.pprint(client.insert('Dictionary', word_from, colPath, word_to, timestamp, ConsistencyLevel.ONE,)) | ret = client.insert('Dictionary', word_from, colPath, word_to, timestamp, ConsistencyLevel.ONE,) |
| if ret is None: |
| print "inserted word "+word_from+" ("+lang_from+")" + " - " +word_to+" ("+lang_to+")" |
| else: |
| print ret |
| |
def removeWord(self, lang_from, lang_to, word_from): | def removeWord(self, lang_from, lang_to, word_from): |
colPath = ColumnPath("Words", lang_from, lang_to) | colPath = ColumnPath("Words", lang_from, lang_to) |
timestamp = int(time.time()) | timestamp = int(time.time()) |
pp.pprint(client.remove('Dictionary', word_from, colPath, timestamp, ConsistencyLevel.ONE,)) | ret = client.remove('Dictionary', word_from, colPath, timestamp, ConsistencyLevel.ONE,) |
| if ret is None: |
| print "removed word " + word_from + " ("+lang_from+" - "+lang_to+")" |
| |
| |
dic.addWord("pl","de","dom","house") | dic.addWord("pl","de","dom","house") |
dic.addWord("pl","cz","dom","holpiczka") | dic.addWord("pl","cz","dom","holpiczka") |
| |
| print |
| |
dic.removeWord("pl","de","dom") | dic.removeWord("pl","de","dom") |
| |
| print |
| |
dic.translate("pl", "dom", "en") | dic.translate("pl", "dom", "en") |
| dic.translate("pl", "dom", "cz") |
| dic.translate("pl", "dom", "de") |
| |
| print |
| |
dic.getAllTranslates("pl","dom") | dic.getAllTranslates("pl","dom") |
| |