1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-11 13:10:58 +00:00

Add similarity comparison to String

Uses the Sorensen-Dice coefficient to calculate similarity. This also adds
String.bigrams() as a convenience function needed by the comparison.
This commit is contained in:
George Marques
2016-06-13 14:06:03 -03:00
parent f47d7b27cb
commit 1b8d0a16b7
3 changed files with 50 additions and 0 deletions

View File

@@ -249,6 +249,8 @@ static void _call_##m_type##_##m_method(Variant& r_ret,Variant& p_self,const Var
VCALL_LOCALMEM1R(String,ends_with);
VCALL_LOCALMEM1R(String,is_subsequence_of);
VCALL_LOCALMEM1R(String,is_subsequence_ofi);
VCALL_LOCALMEM0R(String,bigrams);
VCALL_LOCALMEM1R(String,similarity);
VCALL_LOCALMEM2R(String,replace);
VCALL_LOCALMEM2R(String,replacen);
VCALL_LOCALMEM2R(String,insert);
@@ -1274,6 +1276,8 @@ _VariantCall::addfunc(Variant::m_vtype,Variant::m_ret,_SCS(#m_method),VCALL(m_cl
ADDFUNC1(STRING,BOOL,String,ends_with,STRING,"text",varray());
ADDFUNC1(STRING,BOOL,String,is_subsequence_of,STRING,"text",varray());
ADDFUNC1(STRING,BOOL,String,is_subsequence_ofi,STRING,"text",varray());
ADDFUNC0(STRING,STRING_ARRAY,String,bigrams,varray());
ADDFUNC1(STRING,REAL,String,similarity,STRING,"text",varray());
ADDFUNC2(STRING,STRING,String,replace,STRING,"what",STRING,"forwhat",varray());
ADDFUNC2(STRING,STRING,String,replacen,STRING,"what",STRING,"forwhat",varray());