如何访问 iPhone/iPod 的内置(可能是预测性)字典

发布于 2024-09-13 16:39:50 字数 144 浏览 8 评论 0原文

我正在编写一个应用程序,它有自己的文本输入,覆盖通常的键盘。我想包括某种单词补全。出于显而易见的原因,如果我不必提供自己的词典,而是可以使用已有的词典,那将是最好的。

有谁知道如何访问这本词典吗?有可能吗?如果是的话:它有什么能力?

提前致谢

I'm writing an app that has it's own text input, overriding the usual keyboard. I want to include some kind of word completition. It would, for obvious reasons, be best, if I wouldn't have to supply my own dictionary, but instead could use the one already in place.

Does anyone know how to access this dictionary? Is it even possible? And if it is: what capabilities does it have?

Thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

妄想挽回 2024-09-20 16:39:50

嗨,我正在寻找同样的东西 - 但到目前为止还没有成功。然而我发现的是C中的T9算法。您需要的是可以从 字典文件 创建的字典数据库,例如作为 dict.cc 或使用 Arun Prabhakar 的样本词典

希望这有帮助。

请参阅下面的 Arun Prabhakar 网站 中的代码(我我不是此代码的作者!):

    /*
t9.c
Dependency : t9.dic
A file with lots of words to populate our t9 trie structure.
All in small letter no spaces no other characters
Terminated by a line with only a 0 (zero)
=================
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

struct t9
{
 struct t9 * node[27];
};

struct t9 * t9_new()
{
 struct t9 * r =  (struct t9 *)malloc(sizeof(struct t9));

 int i=0;
 for(;i<27;i++) r->node[i] = (struct t9 *)0;

 return r;
}

void t9_free(struct t9 * root)
{
 if(root)
 {
  int i=0;
  for(;i<27;i++)
   t9_free(root->node[i]);
  free(root);
 }
}

struct t9 * t9_insert(struct t9 * root ,char *val)
{

 if(!root){ root = t9_new(); }

 if(!*val) return root;
 *val |= ('A' ^ 'a');
 char c = *val - 'a';
        root->node[c] = t9_insert(root->node[c] ,++val);

 return root;
}

void t9_print(char *pre, struct t9 * root,int depth)
{
 int i=0,flag=0;
 for(;i<27;i++)
 {
  if(root->node[i])
  {
   pre[depth]='a'+i;flag=1;
   t9_print(pre,root->node[i],depth+1);
   pre[depth]=0;
  }
 }
 if(flag == 0)
 {
  pre[depth]=0;
  printf("%s\n",pre);
 }
}

int in_mob_ks(struct t9 * root,char val,int o)
{

 int a[]={0,3,6,9,12,15,19,22,26};
 /* 2=>0 1 2 
    3=>3 4 5
    4=>6 7 8
    5=>9 10 11
    6=>12 13 14
    7=>15 16 17 18
    8=>19 20 21
    9=>22 23 24 25
  */
 if(o && o>=a[val+1]) return -1;


 int s=o?o:a[val];
 int e=a[val+1];
 //printf("From %d-%d",s,e);
 for(;s<e;s++)
  if(root->node[s])
   return s;
 return -1;
}

void t9_search_mob(char *pre, struct t9 * root,int depth,char *val)
{

 if(*(val+depth)==0)
 {
  pre[depth]=0;
  t9_print(pre,root,depth);
  return;
 }

 int i=in_mob_ks(root,*(val+depth)-'2',0);
 if(i==-1)
 {
  pre[depth]=0;
  //printf("%s\n",pre);
 }
 while(i>=0)
 {
  pre[depth]=i+'a';
  t9_search_mob(pre,root->node[i],depth+1,val);
  pre[depth]=0;
  i=in_mob_ks(root,*(val+depth)-'2',i+1);
 }
}


struct t9 * t9_search(struct t9 * root, char *val)
{
 while(*val)
 {
  if(root->node[*val-'a'])
  {
   root = root->node[*val-'a'];
   val++;
  }
  else return NULL;
 }
 return root;
}

int main()
{
 struct t9 * root = (struct t9 *) 0;
 char a[100],b[100];int i;
 FILE *fp = fopen("t9.dic","r");
 while(!feof(fp))
 {
  fscanf(fp,"%s",&a);
  if(a[0]=='0')break;
  root=t9_insert(root,a);
 }

 while(1)
 {
  printf("mob keys 2-9:");
  scanf("%s",&a);
  if(a[0]=='0')break;
  t9_search_mob(b,root,0,a);
 }
 t9_free(root);
}

Hi I am looking for the same - so far unsuccessful though. What I found however is the T9 algorithm in C. What you would need is the dictionary database which you could create from a dictionary file such as dict.cc's or use Arun Prabhakar's sampel dictionary.

Hope this helped.

See code from Arun Prabhakar's website bleow (I am not the author of this code!):

    /*
t9.c
Dependency : t9.dic
A file with lots of words to populate our t9 trie structure.
All in small letter no spaces no other characters
Terminated by a line with only a 0 (zero)
=================
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

struct t9
{
 struct t9 * node[27];
};

struct t9 * t9_new()
{
 struct t9 * r =  (struct t9 *)malloc(sizeof(struct t9));

 int i=0;
 for(;i<27;i++) r->node[i] = (struct t9 *)0;

 return r;
}

void t9_free(struct t9 * root)
{
 if(root)
 {
  int i=0;
  for(;i<27;i++)
   t9_free(root->node[i]);
  free(root);
 }
}

struct t9 * t9_insert(struct t9 * root ,char *val)
{

 if(!root){ root = t9_new(); }

 if(!*val) return root;
 *val |= ('A' ^ 'a');
 char c = *val - 'a';
        root->node[c] = t9_insert(root->node[c] ,++val);

 return root;
}

void t9_print(char *pre, struct t9 * root,int depth)
{
 int i=0,flag=0;
 for(;i<27;i++)
 {
  if(root->node[i])
  {
   pre[depth]='a'+i;flag=1;
   t9_print(pre,root->node[i],depth+1);
   pre[depth]=0;
  }
 }
 if(flag == 0)
 {
  pre[depth]=0;
  printf("%s\n",pre);
 }
}

int in_mob_ks(struct t9 * root,char val,int o)
{

 int a[]={0,3,6,9,12,15,19,22,26};
 /* 2=>0 1 2 
    3=>3 4 5
    4=>6 7 8
    5=>9 10 11
    6=>12 13 14
    7=>15 16 17 18
    8=>19 20 21
    9=>22 23 24 25
  */
 if(o && o>=a[val+1]) return -1;


 int s=o?o:a[val];
 int e=a[val+1];
 //printf("From %d-%d",s,e);
 for(;s<e;s++)
  if(root->node[s])
   return s;
 return -1;
}

void t9_search_mob(char *pre, struct t9 * root,int depth,char *val)
{

 if(*(val+depth)==0)
 {
  pre[depth]=0;
  t9_print(pre,root,depth);
  return;
 }

 int i=in_mob_ks(root,*(val+depth)-'2',0);
 if(i==-1)
 {
  pre[depth]=0;
  //printf("%s\n",pre);
 }
 while(i>=0)
 {
  pre[depth]=i+'a';
  t9_search_mob(pre,root->node[i],depth+1,val);
  pre[depth]=0;
  i=in_mob_ks(root,*(val+depth)-'2',i+1);
 }
}


struct t9 * t9_search(struct t9 * root, char *val)
{
 while(*val)
 {
  if(root->node[*val-'a'])
  {
   root = root->node[*val-'a'];
   val++;
  }
  else return NULL;
 }
 return root;
}

int main()
{
 struct t9 * root = (struct t9 *) 0;
 char a[100],b[100];int i;
 FILE *fp = fopen("t9.dic","r");
 while(!feof(fp))
 {
  fscanf(fp,"%s",&a);
  if(a[0]=='0')break;
  root=t9_insert(root,a);
 }

 while(1)
 {
  printf("mob keys 2-9:");
  scanf("%s",&a);
  if(a[0]=='0')break;
  t9_search_mob(b,root,0,a);
 }
 t9_free(root);
}
无言温柔 2024-09-20 16:39:50

如果您只需要拼写检查功能,也许您可​​以使用 UITextChecker ?

过去,我需要快速访问完整的词典,我的解决方案是在我的应用程序中嵌入离线词典。后来我把它变成了一个其他人可以使用的静态库(只需支付少量费用)。它没有“预测”功能,但如果您确实需要一本完整的词典,可以在 www.lexicontext 上查看。 .com

If you just need spell-checking capabilities, maybe you can use UITextChecker ?

In the past I needed quick access to a full-blown dictionary and my solution was to embed an offline dictionary inside my app. I later turned it into a static library that others can use (for a small fee). It doesn't have "predictive" capabilities, but if you do need a full-blown dictionary you can check it out at www.lexicontext.com

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文