MCPcopy Index your code
hub / github.com/UCL-CREST/Siamese

github.com/UCL-CREST/Siamese @v.0.6

Chat with this repo
repository ↗ · DeepWiki ↗ · release v.0.6 ↗ · + Follow
16,634 symbols 94,013 edges 14,963 files 93 documented · 1%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Siamese: Code Clone Search Engine

Siamese logo

Siamese is a code clone search system powered by Elasticsearch with code clone detection approaches, code normalisation and ngram-based matching, built on top. It can scalably search for clones of type-1 to type-3 from a large corpora of Java source code within seconds.

Note: Siamese stands for Scalalbe, Iusingnstant, And Multi-Representation

Analyse term frequency and document frequency of terms in the index

  1. Modify the class TermFreqAnalyser with appropriate configurations
  2. The result frequency files will be generated (e.g. freq_df_src.csv, freq_df_toksrc.csv). The one without tok means the normalised source code tokens, whilst the one with tok means the original source code tokens.
  3. Modify the sort_term.py script with the generated result frequency files and run the script.
  4. Graphs will be genearated. They follow Zipf's law. Hooray!

Setup:

  1. Download elasticsearch-2.2.0
wget https://download.elasticsearch.org/elasticsearch/release/org/elasticsearch/distribution/tar/elasticsearch/2.2.0/elasticsearch-2.2.0.tar.gz

And extract it to the disk.

tar -xvf elasticsearch-2.2.0.tar.gz
rm elasticsearch-2.2.0.tar.gz
  1. Modify the configuration file in config/elasticsearch.yml
cluster.name: stackoverflow
index.query.bool.max_clause_count: 4096
  1. Clone the project from GitHub.
git clone git@github.com:cragkhit/elasticsearch.git
  1. Install Maven.
sudo apt-get update
sudo apt-get install maven
  1. Run elasticsearch
./elasticsearch-2.2.0/bin/elasticsearch -d
  1. Install JDK
sudo apt-get install default-jdk
  1. Set JAVA_HOME
vim /etc/environment

and paste the location of JAVA_HOME into the file. Note: finding JAVA_HOME by

whereis javac
ls -l <the path>
... keep following the path
  1. Configure config.properties file with appropriate settings

  2. Execute the experiment.

mvn compile exec:java -Dexec.mainClass=crest.siamese.Main -Dexec.args="-cf config.properties"

Early Experimental Results

No. of combinations of IR scoring parameter I searched for:

Func. n-gram code norm. params Total
TF-IDF 4 64 3 768
BM25 4 64 552 12800
DFR 4 64 735 26880
IB 4 64 225 5120
LM Dirichlet 4 64 6 1536
LM Jelinek Mercer 4 64 10 2560
Grand total 49664

Misc.

Read Lucene index direclty:

  • http://stackoverflow.com/questions/20575254/lucene-4-4-how-to-get-term-frequency-over-all-index
  • http://stackoverflow.com/questions/16847857/how-do-you-read-the-index-in-lucene-to-do-a-search

Extension points exported contracts — how you extend this code

WritableComparable (Interface)
A Writable which is also Comparable. WritableComparable s can be compared to each other,
resources/tests/WritableComparable.java
Tokenizer (Interface)
(no doc) [2 implementers]
src/crest/siamese/helpers/Tokenizer.java
Normalizer (Interface)
(no doc) [2 implementers]
src/crest/siamese/helpers/Normalizer.java
MethodParser (Interface)
(no doc) [2 implementers]
src/crest/siamese/helpers/MethodParser.java

Core symbols most depended-on inside this repo

close
called by 10995
bcb_chosen_clones/selected#585982#51#63.java
write
called by 6923
bcb_chosen_clones/selected#33404#64#89.java
append
called by 6718
bcb_chosen_clones/selected#84634#87#94.java
add
called by 5537
bcb_chosen_clones/selected#14541#57#85.java
toString
called by 5163
bcb_chosen_clones/selected#760300#71#89.java
equals
called by 4941
bcb_chosen_clones/selected#63093#162#242.java
getName
called by 4452
bcb_chosen_clones/selected#2385054#28#70.java
get
called by 3395
bcb_chosen_clones/default#97704#45#69.java

Shape

Method 16,392
Class 184
Function 54
Interface 4

Languages

Java99%
Python1%
C++1%

Modules by API surface

src/crest/siamese/main/Siamese.java43 symbols
resources/lexer_test/JavaCore.java34 symbols
src/crest/siamese/test/LicenseExtractorTest.java31 symbols
src/crest/siamese/document/Document.java29 symbols
src/crest/siamese/document/Method.java26 symbols
src/crest/siamese/settings/NormalizerMode.java22 symbols
src/crest/siamese/helpers/JavaMethodParser.java19 symbols
src/crest/siamese/experiment/BCBExperiment.java18 symbols
ninka-1.3/comments/io.cpp17 symbols
src/crest/siamese/helpers/ESConnector.java16 symbols
src/crest/siamese/settings/IndexSettings.java15 symbols
src/crest/siamese/test/JavaNormalizerTest.java13 symbols

Datastores touched

(mysql)Database · 1 repos
wdbDatabase · 1 repos
ODM-GammaDatabase · 1 repos
mysqlDatabase · 1 repos
osDatabase · 1 repos
inventoryDatabase · 1 repos
bcmedDatabase · 1 repos
citeseerDatabase · 1 repos

For agents

$ claude mcp add Siamese \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact