编码挑战:检测不良语法 [英] Coding challenge: detect poor grammar

查看:117
本文介绍了编码挑战:检测不良语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

老师正在标记一堆英语作业,而且时间不多了。为了加快标记过程,教师决定他将失败任何拼写错误,拼写错误或资本化不正确(或大写)的作业。



用您选择的任何语言编写一个函数,它将获取一段文本并确定它是否通过了集合。由你决定什么构成坏文本。你甚至可能想得分,但简单的yay / nay也可以。



你可能会看到一些文字的例子:



快速的棕色狐狸跳过懒狗

快速的棕色狐狸跳过懒狗。



今天下雨天



我沿着海滩散步



这句话有双字吗?



我错过了一个问号。



我在找狗



部分资源:



  • 大型英语词汇单词列表(ESL / EFL) [ ^ ]

  • C#Library for Grammar and Spell Checking [< a href =https:// www。 codeproject.com/Articles/209514/Csharp-Library-for-Grammar-and-Spell-Checkingtarget =_ blanktitle =New Window> ^ ]

  • 截止日期后的语法和拼写检查规则 [ ^ ]

  • A teacher is marking a bunch of English assignments and is running out of time. In order to expedite the marking process the teacher has decided that he will fail any assignment that has bad spelling, typos or incorrect capitalisation (or capitalization).

    Write a function, in any language you choose, that will take a piece of text and decide if it passes muster. It's up to you to decide what constitutes a "bad" piece of text. You may even want to score it, but a simple yay / nay is OK, too.

    Some examples of text you may be presented with:

    "The quick brown fox jumped over the lazy dog"
    "The quick brown fox jumped over the lazy dog."

    "Its a rainy day today"

    "i was walking along beach"

    "Does this sentence have have a double word?"

    "Am I missing a question mark."

    "I looking for dog"

    Some resources:


    • Large English Vocabulary Word Lists (ESL/EFL)[^]
    • C# Library for Grammar and Spell Checking[^]
    • After the Deadline grammar and spell checking rules[^]
    • 推荐答案

      这是一个使用API​​服务的快速'n'脏解决方案。可悲的是,服务不如Grammarly ...

      Here is a quick 'n' dirty solution using an API service. Sadly the service is not as good as Grammarly...
      using Newtonsoft.Json;
      using System;
      using System.Collections.Generic;
      using System.Linq;
      using System.IO;
      using System.Net;
      
      namespace TextGearsApi
      {
          class Program
          {
              static void Main(string[] args)
              {
                  Console.WriteLine("Coding challenge: detect poor grammar");
                  Console.WriteLine("=====================================\n");
      
                  // Get you API key here: https://textgears.com
                  var api = new TextGearsApi("[key_goes_here");
      
                  for (;;)
                  {
                      Console.Write("Text to check: ");
                      var text = Console.ReadLine();
                      if (string.IsNullOrEmpty(text)) break;
      
                      try
                      {
                          var result = api.Check(text);
                          if (result?.Errors?.Count != 0)
                          {
                              Console.WriteLine("Recommendations:");
                              for (int i = 0; i < result.Errors.Count; i++)
                              {
                                  var item = result.Errors[i];
                                  Console.WriteLine(


      {i + 1}: {item.Bad}>> {string.Join( ,item.Better。选择(x =>
      " {i + 1}: {item.Bad} >> {string.Join(", ", item.Better.Select(x =>


      \ { x} \))} );
      }
      Console.WriteLine();
      }
      其他
      {
      Console.WriteLine(
      看起来没问题。\ n < span class =code-string>);
      }
      }
      catch(exception ex)
      {
      Console.WriteLine(
      "\"{x}\""))}"); } Console.WriteLine(); } else { Console.WriteLine("Looks okay.\n"); } } catch (Exception ex) { Console.WriteLine(


      这篇关于编码挑战:检测不良语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆