I have a word like "itibarsızlaştırmak".
The stem is "itibar" and the suffix list is "a, ak, ar, ı, laş, m, sız, i".
The suffix list is missing. "ma, tır, ız, i, ı, a, m, sı, mak, tı, sız, ak, ar, laş" is the right one.
How can i to reach "itibarsızlaştırmak" with suffix list in which order?
For Example : itibar + suffixList[6] -> itibarsız
itibar + suffixList[6] + suffixList[5] -> itibarsızlaş
Words and suffix list changes all time. So I need a algorithm for it. I tried merge suffix one by one with stem and comparision but it is not work for all list.
Thanks.
Using a Dictionary with assigned suffixes to words is a way of achieving this.
This code does however needs to be tweaked to discern suffixes not in the list and suffixes that are similar (like 'a' and 'ak' in your example).
Fixed the search pattern for the suffixes.
using System;
using System.Collections.Generic;
using System.Linq;
public class Program
{
public static void Main()
{
var words = new Dictionary<string, List<string>>();
words.Add("itibar", new List<string>(){"ma", "tır", "ız", "i", "ı", "a", "m", "sı", "mak", "tı", "sız", "ak", "ar", "laş"}.OrderBy(e => e.Length).ToList());
var word = "itibarsızlaştırmak";
var wordUsed = words.FirstOrDefault(e => word.Contains(e.Key));
var suffixesUsedInOrder = new List<string>();
var charsToSearch = "";
foreach (var character in word.Substring(wordUsed.Key.Length))
{
var a = character.ToString();
if (charsToSearch.Length > 0)
{
a = charsToSearch + a;
}
if (!wordUsed.Value.Any(e => e == a) || wordUsed.Value.Count(e => e.StartsWith(a)) > 1)
{
charsToSearch += character.ToString();
}
else
{
suffixesUsedInOrder.Add(wordUsed.Value.FirstOrDefault(e => e == a));
charsToSearch = "";
}
}
Console.WriteLine(string.Join(",", suffixesUsedInOrder));
}
}
The result of this code run: sız,laş,tır,mak