<jupyter_start><jupyter_text>Canonicalize<jupyter_code>canonical_file = os.path.join(temp_dir,canonical)
!tl canonicalize -c "$wikify_column_name" --add-context $table_path > $canonical_file
pd.read_csv(canonical_file, nrows = 10)<jupyter_output><empty_output><jupyter_text>Candidate Generation<jupyter_code>%%time
candidates_file = os.path.join(temp_dir,candidates)
aux_field = 'graph_embedding_complex'
!tl clean -c label -o label_clean $canonical_file \
        / --url http://ckg06:9200 --index wikidatadwd-augmented-01 get-fuzzy-augmented-matches -c label_clean \
        --auxiliary-fields $aux_field \
        --auxiliary-folder $temp_dir \
        / --url http://ckg06:9200 --index wikidatadwd-augmented-01 get-exact-matches \
        -c label_clean --auxiliary-fields $aux_field \
        --auxiliary-folder $temp_dir > $candidates_file
                
for field in aux_field.split(','):
    aux_list = []
    for f in glob.glob(f'{temp_dir}/*{aux_field}.tsv'):
        aux_list.append(pd.read_csv(f, sep='\t', dtype=object))
    aux_df = pd.concat(aux_list).drop_duplicates(subset=['qnode']).rename(columns={aux_field: 'embedding'})
    aux_df.to_csv(f'{temp_dir}/{aux_field}.tsv', sep='\t', index=False)
pd.read_csv(candidates_file,nrows = 10)<jupyter_output><empty_output><jupyter_text>Feature Voting<jupyter_code>%%time
feature_votes_file = os.path.join(temp_dir,feature_votes)
!tl smallest-qnode-number $candidates_file \
    / string-similarity -i --method monge_elkan:tokenizer=word -o monge_elkan \
    / string-similarity -i --method jaccard:tokenizer=word -c kg_descriptions context -o des_cont_jaccard \
    / feature-voting -c "pagerank,smallest_qnode_number,monge_elkan,des_cont_jaccard" > $feature_votes_file
pd.read_csv(feature_votes_file,nrows = 10)<jupyter_output><empty_output><jupyter_text>Compute Embedding Score using Column Vector Strategy<jupyter_code>%%time
score = os.path.join(temp_dir,score_file)
!tl score-using-embedding $feature_votes_file --column-vector-strategy centroid-of-singletons -o graph-embedding-score \
--embedding-file $embedding_file \
> $score
pd.read_csv(score,nrows = 10)<jupyter_output><empty_output><jupyter_text>Compute final score<jupyter_code>final_score = os.path.join(temp_dir,'final_score.csv')
!tl normalize-scores -c graph-embedding-score -t zscore -o normalized-graph-embedding-score $score \
    / normalize-scores -c pagerank -t zscore -o normalized-pagerank \
    / normalize-scores -c monge_elkan -t zscore -o normalized-monge-elkan \
    / combine-linearly -w normalized-graph-embedding-score:1,normalized-pagerank:1,normalized-monge-elkan:1 \
     -o final_score > $final_score
df = pd.read_csv(final_score)
df.head()<jupyter_output><empty_output><jupyter_text>Get Top5 KG Links<jupyter_code>linked_table_name = "topk-" + table_name
output_path = os.path.join(temp_dir,linked_table_name)
!tl get-kg-links -c final_score -l label -k 5 $final_score > $output_path
pd.read_csv(output_path, nrows = 10)<jupyter_output><empty_output><jupyter_text>Join to Produce final result<jupyter_code>final_output = 'linked-' + table_name
path = os.path.join(table,final_output)
!tl join -f $table_path --csv -c ranking_score $output_path > $path<jupyter_output><empty_output><jupyter_text>CleanUp temporary files<jupyter_code>shutil.rmtree(temp_dir)<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup