Select to view content in your preferred language

Can u help me in this one?

342
2
03-09-2014 06:09 PM
PeterPete
New Contributor
Please can u help me in the third function because I am desperate to know how should I do it


def split_on_separators(original, separators):
""" (str, str) -> list of str

Return a list of non-empty, non-blank strings from the original string
determined by splitting the string on any of the separators.
separators is a string of single-character separators.

>>> split_on_separators("Hooray! Finally, we're done.", "!,")
['Hooray', ' Finally', " we're done."]
"""
result = []
newstring = ''

for index,char in enumerate(original):
if char in separators or index==len(original) -1:
result.append(newstring)
newstring=''
if '' in result:
result.remove('')
else:
newstring+=char
return result
def average_sentence_length(text):
""" (list of str) -> float

Precondition: text contains at least one sentence. A sentence is defined
as a non-empty string of non-terminating punctuation surrounded by
terminating punctuation or beginning or end of file. Terminating
punctuation is defined as !?.

Return the average number of words per sentence in text.

>>> text = ['The time has come, the Walrus said\n',
'To talk of many things: of shoes - and ships - and sealing wax,\n',
'Of cabbages; and kings.\n'
'And why the sea is boiling hot;\n'
'and whether pigs have wings.\n']
>>> average_sentence_length(text)
17.5
"""
words=0
import re
for line in text:
line_values = list(filter(("-").__ne__, line.strip().split()))
words += len(line_values)

sentence =[x for x in re.compile('[.!?]').split(''.join(text).strip()) if x]
ASL=words/len(sentence)
return ASL

def avg_sentence_complexity(text):
""" (list of str) -> float

Return the average number of phrases per sentence.

A sentence is defined as a non-empty string of non-terminating
punctuation surrounded by terminating punctuation
or beginning or end of file. Terminating punctuation is defined as !?.
Phrases are substrings of sentences, separated by one or more of the
following delimiters ,;:

>>> text = ['The time has come, the Walrus said\n',
'To talk of many things: of shoes - and ships - and sealing wax,\n',
'Of cabbages; and kings.\n',
'And why the sea is boiling hot;\n',
'and whether pigs have wings.\n']
>>> avg_sentence_complexity(text)
3.5
"""
Sentences=0
Phrases=0
sentence=split_on_separators(text,'?!.')
for sep in sentence:
Sentences+=1
Phrase=split_on_separators(text, ',;:')
for n in Phrase:
Phrases+=1
complex = float(Phrases) / float(Sentences)
return complex
Tags (2)
0 Kudos
2 Replies
RichardFairhurst
MVP Honored Contributor
Please explain what you are going to do with this in ArcMap.  You have gotten help before and yet you keep asking for more on the same topic.  What are all these requests accomplishing?  Why you are so desperate to do these things?  Are these functions being developed for class assignments?

I cannot fit these functions to any obvious discipline that uses ArcMap.
0 Kudos
XanderBakker
Esri Esteemed Contributor
I second Richard on this. What does the comparison of linguistic signatures has to do with GIS?

In the recent past I answered a post similar to yours, here:
http://forums.arcgis.com/threads/103785-Hey-I-was-wondering-about-this-function-problem-for-a-while

Since all you posts are not related to GIS, you can probably better take your questions to a forum like stackoverflow?
0 Kudos