Hi Everyone,
Can you tell me why this code returns a different set of results each time the app is run?
This code downloads web pages from dictionary.com it lets you know if a particular word is a noun or not a noun.
The words that are sent to dictionary.com are:
this
is
a
test
I was expecting that "a" and "test" would be flagged as a noun but the results returned are not consistant. If I go to dictionary.com and do it manually, it returns the correct results.
Can you tell me if I did the coding wrong?
Is the fault with my coding or with dictionary.com maybe?
If you run this coding you can see the strange behaviour.
Can you tell me why this code returns a different set of results each time the app is run?
This code downloads web pages from dictionary.com it lets you know if a particular word is a noun or not a noun.
The words that are sent to dictionary.com are:
this
is
a
test
I was expecting that "a" and "test" would be flagged as a noun but the results returned are not consistant. If I go to dictionary.com and do it manually, it returns the correct results.
Can you tell me if I did the coding wrong?
Is the fault with my coding or with dictionary.com maybe?
If you run this coding you can see the strange behaviour.
B4X:
'Activity module
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim b4a As String
Dim strDownloadList As List
Dim listWords As List
End Sub
Sub Activity_Create(FirstTime As Boolean)
b4a = "http://dictionary.reference.com/browse/"
listWords.Initialize
listWords.Add("this")
listWords.Add("is")
listWords.Add("a")
listWords.Add("test")
strDownloadList.Initialize
strDownloadList.Add(b4a & "this")
strDownloadList.Add(b4a & "is")
strDownloadList.Add(b4a & "a")
strDownloadList.Add(b4a & "test")
HttpUtils.CallbackActivity = "Main" 'Current activity name.
HttpUtils.CallbackJobDoneSub = "JobDone"
HttpUtils.CallbackUrlDoneSub = "UrlDone"
HttpUtils.DownloadList("JobDone", strDownloadList)
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub JobDone (Job As String)
ToastMessageShow("Processing all done.", False)
End Sub
Sub UrlDone(Url)
Dim strEntireWebPage As String
Dim strSearchWord As String
' ToastMessageShow("Processing URL: " & Url, False)
' ToastMessageShow("URL number: " & HttpUtilsService.countWorking, False)
If HttpUtils.IsSuccess(Url) Then
s = HttpUtils.GetString(Url)
' ToastMessageShow(s,True)
' Replace double quotes with single quotes for easy handling because I am using strings.
'---------------------------------------------------------------------------------------
s = s.Replace(QUOTE, "'")
' Trim down the entire web page so only the deffinition is left.
'---------------------------------------------------------------
s = s.SubString(s.IndexOf("<div class='pbk'><span class='pg'>") + 34) 'Add 34 so we grab the definition after the tag
s = s.SubString2(0, s.IndexOf("</span>")) 'Grab only the definition enclosed
' See if the word is a noun.
'---------------------------
If s.ToUpperCase.Trim = "NOUN" Then
ToastMessageShow(listWords.Get(HttpUtilsService.countWorking) & " *** is a noun.", False)
Else
ToastMessageShow(listWords.Get(HttpUtilsService.countWorking) & " *** is NOT a noun.", False)
End If
End If
End Sub
Last edited: