1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Ratling [72]
3 years ago
10

Software, such as a word processor, search engine, or mobile interface, typically includes plug-in support specific to a languag

e to aid with spelling. In this assignment, you will implement a class that provides general language support; such a class could presumably be (re)used in these broader software applications. For the purpose of spell checking, a simple language model is a set of valid words. By convention, a language specification may include both capitalized and uncapitalized words. A word that is is entirely lowercased in the language specification can be used in either capitalized or uncapitalized from (e.g., if 'dog'is in the language specification, then both 'dog' and 'Dog' are legitimate usages). However, any word that includes one or more uppercased letters in the original language reflects a form that cannot be modified (e.g., 'Missouri' is acceptable but 'missouri' is not; 'NATO' is acceptable, but neither 'Nato', 'nato', nor 'nAto' would be acceptable). The goals of the new class will be to answer the following types of queries: • Is a given string a legitimate word in the language? (based on the above conventions regarding capitalization) • Given a string, which may or may not be in the language, produce a list of suggestions that are valid words in the language and reasonably "close" to the given string in terms of spelling. (We will say more below, about the notion of distance between words.) Formally, you are to provide a file named language_tools.py that defines aLanguageHelper class with the following three methods. _init__(self, words) The words parameter can be any iterable sequence of strings that define the words in the language. For example, the parameter may be a list of strings, or a file object that has one word per line. All you should assume about this parameter is that you are able to do a loop, for w in words: to access its entries. The class is responsible for recording all words from the language into an internal data representation, and stripping any extraneous whitespace from each entry (such as newline characters that will appear in a file). For the sake of efficiency, we recommend that you store the language words in a Python set instance. (We discuss sets in a later section.) _contains_(self, query) The query parameter is a string. This method should determine whether the string is considered a legitimate word, returning True if the word is contained in the language and False otherwise. This method should adhere to the aforementioned conventions regarding capitalized and uncapitalized words. For example, dog, Dog and Missouri are contained in the English language, yet missouri and Missourri are not. The _contains_ special method is used by Python to support the in operator. It allows the standard syntax "Missouri' in language which is implicitly translated by Python to the internal call language. _contains_('Missouri') presuming that language is an instance of our LanguageHelper class. getSuggestions (self, query) Given a query string, this method should return an alphabetical list of "nearby" words in the language. Doing a good job at offering suggestions is the most difficult part of writing a good language helper. We discuss this aspect of the project in a later section. S = set() create a new set instance (which is initially an empty set). s.add(value) adds the given value to the set (value will be a string in our application). value in s returns True if the given value is currently in the set, and False otherwise.
Engineering
1 answer:
bearhunter [10]3 years ago
7 0

Answer:

Check the explanation

Explanation:

class LanguageHelper:

language=set()

#Constructor

def __init__(self, words):

for w in words:

self.language.add(w)

def __contains__(self,query):

return query in self.language

def getSuggestionns(self,query):

matches = []

for string in self.language:

if string.lower().startswith(query) or query.lower().startswith(string) or query.lower() in string.lower():

matches.append(string)

return matches

lh = LanguageHelper(["how","Hi","What","Hisa"])

print('how' in lh)

print(lh.getSuggestionns('hi'))

===========================================

OUTPUT:-

==================

True

['Hisa', 'Hi']

====

You might be interested in
The parts of a feature control frame are the tolerance value, the datum references, and the
Elan Coil [88]

Answer:

d

Explanation:

4 0
3 years ago
Conduct online research and write a short report on the origin and evolution of the meter as a measurement standard. Discuss how
valina [46]

Answer:

People have come up with all sorts of inventive ways of measuring length. The most intuitive are right at our fingertips. That is, they are based upon the human body: the foot, the hand, the fingers or the length of an arm or a stride.

In ancient Mesopotamia and Egypt, one of the first standard measures of length used was the cubit. In Egypt, the royal cubit, which was used to build the most important structures, was based on the length of the pharaoh’s arm from elbow to the end of the middle finger plus the span of his hand. Because of its great importance, the royal cubit was standardized using rods made from granite. These granite cubits were further subdivided into shorter lengths reminiscent of centimeters and millimeters.

piece of black rock with white Egyptian markings

Fragment of a Cubit Measuring Rod

Credit: Gift of Dr. and Mrs. Thomas H. Foulds, 1925

Later length measurements used by the Romans (who had taken them from the Greeks, who had taken them from the Babylonians and Egyptians) and passed on into Europe generally were based on the length of the human foot or walking and multiples and subdivisions of that. For example, the pace—one left step plus one right step—is approximately a meter or yard. (On the other hand, the yard did not derive from a pace but from, among other things, the length of King Henry I of England’s outstretched arm.) Mille passus in Latin, or 1,000 paces, is where the English word “mile” comes from.

And thus, the meter has and likely will remain so elegantly defined in these terms for the foreseeable future.

Explanation:

is this short enough

5 0
2 years ago
Water flows at low speed through a circular tube with inside diameter of 2 in. A smoothly contoured body of 1.5 in. diameter is
Art [367]

Answer:

Pressure = 11.38 psi

Force = 13.981 Ibf

Explanation:

Step by step solution is in the attached document.

5 0
3 years ago
Which of the eight diagnostic steps for locating an engine performance problem is performed first?
Kay [80]

Answer:

D. Perform a thorough visual inspection.

4 0
2 years ago
Milk has a density of as much as 64.6 lb/ft3. What is the gage pressure at the bottom of the straw 6.1 inches deep in the milk?
gregori [183]

Answer:

Explanation:

1 inch is 0.0833333feet

6.1 inches is 0.5083 feet

Density = mass/volume

64.6 = mass/0.50833

mass = 64.6 x 0.5083 =32.83618lb

3 0
3 years ago
Other questions:
  • Give two methods on how powder is produced in powder metallurgy.
    5·2 answers
  • Design a posttest-only experiment that would test each of the following causal claims. For each one, identify the study’s indepe
    13·1 answer
  • I study to get good grades because my parents want to send me to the college of my choice.” This is an a. Intrinsic motivational
    6·2 answers
  • Which of the following is part of the highway
    11·2 answers
  • An expandable container is filled with 45 in.3 of air and is sitting in ice water that is 32°F. At what volume in in.3 will the
    5·1 answer
  • Electricians will sometimes call ______ "disconnects" or a "disconnecting means."
    15·1 answer
  • Witch one is cuter compared to ur opinion calico kitten or grey?​
    5·1 answer
  • A Styrofoam cup (k = 0.010 W/(m∙ o C)) has cross-sectional area (A) of 3.0 x 10 −2m 2 . The cup is 0.589 cm thick (L). The tempe
    12·1 answer
  • You insert a dielectric into an air-filled capacitor. How does this affect the energy stored in the capacitor?.
    12·1 answer
  • A book sitting on a shelf is an example of ____________.
    6·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!