2016-09-06 5 views
1

私は、生徒が割り当てられた読書に対して短い、毎週の反応を書くクラスを教えます。割り当ては単純なルールに基づいて評価され、そのうちの1つは完璧なスペルです。完璧なスペルは、コンテンツのために時間を費やすことに興味を持っているクラスでの仕事を評価する簡単な方法です。複数の文書をスペルチェックして結果を報告するスクリプト

すべての生徒の提出物を受け取り、スペルが完璧かどうかを1つずつ確認するスクリプトを作成したいと思います。問題は、これをどうやって行うのが最善かわかりません。私が持っていた考えの1つは、それぞれの割り当てを受け取り、それをMicrosoft Wordで実行し、スペルミスの単語の数を収集するPythonスクリプトを書くことでした。しかし、そのようなことも可能ですか?ここでは、そのようなthis.

として、私はMicrosoft Wordのルートが可能であるかどうかわからないんだけど、あなたはAPIを使用することができ

+0

マイクロソフト・ワードは間違いなく行く方法ではありません。ここで

は、私はちょうどあなたがテンプレートとして使用できることを書いたコードのサンプル片です。あなたの仕事をはるかに簡単にする、非常によくpythonにリンクするスペルチェッカーのapiの多くがあります。私はnltkがスペルチェッカーを内蔵していると思うが、私が正しく覚えていれば、[PyEnchant](https://pythonhosted.org/pyenchant/)は本当に良いものだ。 – gowrath

+0

生徒の回答はどのように保存されていますか?あなたはそれらをウェブサイトに入力するように頼んでいるのですか?紙に答えを書いて、その答えをスクリプトに入力していますか?スクリプトに実際の正解を与えるか、またはスクリプトが正解を推測することを期待していますか。より多くの情報をお願いします。 – MooingRawr

+0

@MooingRawr今の投稿は.docx形式ですが、変更されるコメントに基づいています。どんなフォーマットでも、私はすべての投稿をフォルダに保存してから、そのフォルダをスクリプトに送りたいと思っています。プログラムは各提出を繰り返し、スペルミスを報告します。 – invictus

答えて

1

あなたがピップなどを使用してPyEnchantのようなライブラリをスペルチェックをダウンロードした場合は、タスクが大幅にシムですが、 plified。

#!/usr/bin/env python 

import enchant 

THRESHOLD = 1 # harsh 

def numIncorrect(words_in_file): 
    """ 
    @param words_in_file - an iterable of words in the current students submission. 
    @return - the number of misspelled words in this submission. 
    """ 
    word_dict = enchant.Dict("en_US") 
    count = 0 
    for word in file: 
     if not word_dict.check(word): count +=1 
    return count; 


def main(): 
    for filename in os.listdir('.'): # assuming student submissions are in current directory. You can change this depending on how the files are stored (if they are online you could download them etc.) 
     # ... Process filename i.e get student name out and open file, create a list with all its words (one liner) 
     if numIncorrect(words_in_file) > THRESHOLD: 
      # ... mark this student for a deduction 

if __name__ == '__main__': 
    main() 
+0

非常に興味深い。どのような形式の提出物であろうか? – invictus

+0

@invictusここで書いたように、関数numIncorrectは、1人の学生提出物の単語のリスト(または繰り返し可能なもの)を取ります。だから、あなたは最初に言葉のリストを得るために提出書類がどんなフォーマットであっても処理しなければならないでしょう。これはまったく難しいことではありませんが、提出した形式の種類を明確にすれば、より具体的にすることができます。理想的なフォーマットは、ファイル名に生徒の名前が含まれている各生徒の提出用のtxtファイルを含むフォルダです。 – gowrath

1

は、彼らが彼らのドキュメントのWebサイトで持っているJavascriptの例である:

<!DOCTYPE html> 
<html> 
<head> 
<title>JSSample</title> 
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script> 
</head> 
<body> 

<script type="text/javascript"> 
$(function() { 
    var params = { 
     // Request parameters 
     "text": "Bill Gatas", 
     "mode": "{string}", 
     "preContextText": "{string}", 
     "postContextText": "{string}", 
    }; 

    $.ajax({ 
     url: "https://api.cognitive.microsoft.com/bing/v5.0/spellcheck/?" + $.param(params), 
     beforeSend: function(xhrObj){ 
      // Request headers 
      xhrObj.setRequestHeader("Ocp-Apim-Subscription-Key","{subscription key}"); 
     }, 
     type: "GET", 
     // Request body 
     data: "{body}", 
    }) 
    .done(function(data) { 
     alert("success"); 
    }) 
    .fail(function() { 
     alert("error"); 
    }); 
}); 
</script> 
</body> 
</html> 

そして、ここで2つのPythonの例です:

########### Python 2.7 ############# 
import httplib, urllib, base64 

headers = { 
# Request headers 
'Ocp-Apim-Subscription-Key': '{subscription key}', 
} 

params = urllib.urlencode({ 
# Request parameters 
'text': 'Bill Gatas', 
'mode': '{string}', 
'preContextText': '{string}', 
'postContextText': '{string}', 
}) 

try: 
conn = httplib.HTTPSConnection('api.cognitive.microsoft.com') 
conn.request("GET", "/bing/v5.0/spellcheck/?%s" % params, "{body}", headers) 
response = conn.getresponse() 
data = response.read() 
print(data) 
conn.close() 
except Exception as e: 
print("[Errno {0}] {1}".format(e.errno, e.strerror)) 

#################################### 

########### Python 3.2 ############# 
import http.client, urllib.request, urllib.parse, urllib.error, base64 

headers = { 
# Request headers 
'Ocp-Apim-Subscription-Key': '{subscription key}', 
} 

params = urllib.parse.urlencode({ 
# Request parameters 
'text': 'Bill Gatas', 
'mode': '{string}', 
'preContextText': '{string}', 
'postContextText': '{string}', 
}) 

try: 
conn = http.client.HTTPSConnection('api.cognitive.microsoft.com') 
conn.request("GET", "/bing/v5.0/spellcheck/?%s" % params, "{body}", headers) 
response = conn.getresponse() 
data = response.read() 
print(data) 
conn.close() 
except Exception as e: 
print("[Errno {0}] {1}".format(e.errno, e.strerror)) 

#################################### 
+0

これらの例の仕組みを説明できますか? – invictus

+0

確かに、あなたはjavascriptやpythonに興味がありますか? –

+0

DefはPythonバージョンに興味があります。 – invictus

関連する問題