Skip to content

Instantly share code, notes, and snippets.

View NhuanTDBK's full-sized avatar

Steve Tran NhuanTDBK

  • Hanoi, Vietnam
  • 22:23 (UTC +07:00)
View GitHub Profile
@NhuanTDBK
NhuanTDBK / gist:ec706ebb20273eba3deee1ffa26264d8
Created December 19, 2018 11:39
Tensorflow Universal Downloader.py
import tensorflow_hub as hub
TFHUB_URL = "https://tfhub.dev/google/universal-sentence-encoder/2"
sentence_encoder = hub.Module(TFHUB_URL)
val configJanus = new PropertiesConfiguration(configJanusPath)
val graph = JanusGraphFactory.open(configJanus)
// create schema
val tx = graph.buildTransaction().enableBatchLoading().start()
while (iter.hasNext) {
val item = iter.next()
val key = item.getString(0)
val value = item.getString(1)
val productVertex = tx.addVertex(T.label, NodeConstraint.PRODUCT_LABEL)
@NhuanTDBK
NhuanTDBK / reindex.groovy
Created August 1, 2018 04:55
janus_reindex
graph = JanusGraphFactory.open("conf/gremlin-server/janusgraph-cql-es.properties")
mgmt = graph.openManagement()
mgmt.updateIndex(mgmt.getGraphIndex("ByShopIDAndRefID"), SchemaAction.REINDEX).get()
mgmt.updateIndex(mgmt.getGraphIndex("ByShopID"), SchemaAction.REINDEX).get()
graph = JanusGraphFactory.open("conf/gremlin-server/janusgraph-cql-es.properties")
mgmt = graph.openManagement()
mgmt.makePropertyKey("shop_id").dataType(Long.class).cardinality(Cardinality.SINGLE).make()
mgmt.makePropertyKey("ref_id").dataType(Long.class).cardinality(Cardinality.SINGLE).make()
mgmt.commit()
mgmt = graph.openManagement()
shopID = mgmt.getPropertyKey("shop_id")
refId = mgmt.getPropertyKey("ref_id")
map_col = lambda dat,col: col+"-"+dat.map(str)
gen_hash_item = lambda field, feat: '{0}:{1}:1'.format(field,hashstr(feat))
def gen_hash_row(feats,label):
result = []
for idx, item in enumerate(feats):
val = item.split('-')[-1]
if val != 'nan':
result.append(gen_hash_item(idx,item))
lbl = 1
if label == 0:
@NhuanTDBK
NhuanTDBK / 0_reuse_code.js
Created July 11, 2016 07:27
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console