NLTK的拼写检查工具无法正常工作

时间:2016-10-22 04:10:35

标签: python nlp nltk wordnet

我想使用NLTK检查python中句子的拼写。内置spell checker无法正常工作。它将with和'和'作为错误的拼写。

def tokens(sent):
        return nltk.word_tokenize(sent)

def SpellChecker(line):
        for i in tokens(line):
            strip = i.rstrip()
            if not WN.synsets(strip):
                print("Wrong spellings : " +i)
            else: 
                print("No mistakes :" + i)

def removePunct(str):
        return  "".join(c for c in str if c not in ('!','.',':',','))

l = "Attempting artiness With black & white and clever camera angles, the movie disappointed - became even more ridiculous - as the acting was poor and the plot and lines almost non-existent. "
noPunct = removePunct(l.lower())
if(SpellChecker(noPunct)):
        print(l)
        print(noPunct)

有人可以给我理由吗?

1 个答案:

答案 0 :(得分:4)

它提供了错误的拼写,因为它们是//c tree #include<stdio.h> #include<conio.h> struct tree_node { struct tree_node*right,*left; int data; }; struct tree_node*savetemp=NULL; struct tree_node* del(struct tree_node*,int); struct tree_node* insert(struct tree_node*,int); struct tree_node* travel(struct tree_node*,struct tree_node*); void inorder(struct tree_node *); int height(struct tree_node*); int noOfNode(struct tree_node *); void main() { struct tree_node* root=NULL; int item,cho; clrscr(); do { printf("Enter your choice\n"); printf("1.insert 2.delete 3.display 4.no of nodes 5.height 6.exit\n"); scanf("%d",&cho); switch(cho) { case 1:{ printf("Enter element to insert\n"); scanf("%d",&item); root=insert(root,item); } break; case 2:{ printf("Enter element to delete\n"); scanf("%d",&item); root=del(root,item); if(savetemp!=NULL)//condition for any break link is present to insert or not travel(root,savetemp);//to insert break link during insertion } break; case 3:{ printf("inorder travel\n"); inorder(root); } break; case 4:{ printf("No of nodes are: %d\n",noOfNode(root)); } break; case 5: printf("height of tree %d",height(root)); break; case 6: printf("Exiting"); break; default : printf("wrong cho\n"); } }while(cho!=6); getch(); } void inorder(struct tree_node *root) { if (root != NULL) { inorder(root->left); printf("%d \n", root->data); inorder(root->right); } } struct tree_node* insert(struct tree_node*root,int item) { if(root==NULL) { struct tree_node* temp; temp=(struct tree_node*)malloc(sizeof(struct tree_node)); temp->left=NULL; temp->right=NULL; temp->data=item; root=temp; } else { if(root->data<item) { root->right=insert(root->right,item); } else { root->left=insert(root->left,item); } } return(root); } struct tree_node* del(struct tree_node*root,int item) { if(item==root->data) { if(root->left==NULL&&root->right==NULL) //no child { root=NULL; } else if(root->left==NULL||root->right==NULL) //one child { if(root->left!=NULL) //left child { root=root->left; } else //right child { root=root->right; } } else if(root->left!=NULL&&root->right!=NULL) //both child { struct tree_node* temp; savetemp=root->right->left; temp=root; root=root->right; root->left=temp->left; } } else { if(root->data<item) { root->right=del(root->right,item); } else { root->left=del(root->left,item); } } return(root); } struct tree_node* travel(struct tree_node*root,struct tree_node*savetemp) { if (savetemp != NULL) { insert(root,savetemp->data); travel(root,savetemp->left); travel(root,savetemp->right); } return(root); } int height(struct tree_node*root) { int lheight,rheight; if(root==NULL) { return(-1); } else { lheight=height(root->left); rheight=height(root->right); } if(lheight>rheight) { return(lheight+1); } else { return(rheight+1); } } int noOfNode(struct tree_node *root) { static int count=0; if (root != NULL) { noOfNode(root->left); count=count+1; noOfNode(root->right); } return(count); } ,不包含在wordnet中(查看FAQs

因此,您可以使用NLTK语料库中的停用词来检查这些词语。

stopwords