我教一堂课,学生们每周对指定的阅读做简短的反应。作业的评分是基于简单的规则,其中之一是完美的拼写。完美的拼写是一个简单的方法来评估他们的工作,在课堂上,我有兴趣花时间阅读提交的内容。
我想写一个脚本,接受所有学生的意见,并逐个检查拼写是否完美。问题是,我不知道该怎么做。我的一个想法是编写一个Python脚本,它接收每个作业,并通过Microsoft运行它,并收集拼写错误的单词数。但这样的事情可能吗?
发布于 2016-09-06 10:44:55
如果使用pip等下载拼写检查库(如PyEnchant ),则任务将大大简化。
下面是我刚刚编写的一段示例代码,您可以使用这些代码作为模板:
#!/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()
发布于 2016-09-06 10:17:33
我不确定Microsoft路由是否可行,但您可以使用API,例如这。
这里是他们的文档网站上的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>
下面是两个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))
####################################
https://stackoverflow.com/questions/39355375
复制相似问题