All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.shikhir.lsh.untrimmed.forest.shingling.Shingle Maven / Gradle / Ivy

Go to download

This is a simplified implementation for Locality sensitive hashing(LSH) for text documents

The newest version!
package com.shikhir.lsh.untrimmed.forest.shingling;

import com.shikhir.hash.MurmurHash;

public class Shingle implements Comparable {
	private Integer id=null;
	private String token = null;
		
	public Shingle(String token){
		if(token==null) {
			id=0;
			return;
		};
		this.id = MurmurHash.hash32(token);
		this.token = token;
	}
	
	public Integer getId() {
		return id;
	}
	public String getToken() {
		return token;
	}
	public void setToken(String token) {
		this.token = token;
		this.id = MurmurHash.hash32(token);
	}
    public boolean equals(Object o) {
        return (o instanceof Shingle) && (((Shingle) o).getId()).equals(this.getId());
    }

    public int hashCode() {
        return id;
    }

	@Override
	public int compareTo(Shingle that) {
		// TODO Auto-generated method stub
		if(that==null && token==null) {
			return 0;
		}
		else if(that==null){
			throw new IllegalArgumentException();
		}
		int val= this.getId().compareTo(that.getId());
        return val;
	}

	public String toString() {
        return "Shingle [ id: "+id+", token: "+ token+ " ]";
    }
	
	public boolean equals(Shingle that) {
		if(this.id.equals(that.getId())) return true;
		return false;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy