You said:
All the algorithms I've checked so far e.g. n-grams variants, bag of
words etc. are only used for clustering strings that are part of a
context but here is not the case.
However, those algorithms can still be used if you don't treat tokens as full words, but as combinations of characters instead.
Here is an example of such algorithm in Python using Sklearn.
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.cluster import KMeans
data = [
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]'
]
X = TfidfVectorizer(analyzer='char').fit_transform(data)
kmeans = KMeans(n_clusters=2).fit(X)
for cluster in set(kmeans.labels_):
print('\nCluster: {}'.format(cluster))
for i, label in enumerate(kmeans.labels_):
if label == cluster:
print(data[i])
> Cluster: 0
> [email protected]
> [email protected]
> [email protected]
>
> Cluster: 1
> [email protected]
> [email protected]
The major trick is TfidfVectorizer(analyzer='char')
, where you don't treat n-grams of words, but of characters instead.
P.S. If you at some point want to use word n-grams (if you have generally well written sentences) you can use TfidfVectorizer(analyzer='word')
.