![]() |
Google Meinten Sie
Hat jemand von euch schon mal eine Funktion gecoded welche
von einem bestimmten Wort ähnliche Wörter aus Google ausliest. Man gibt z.B Deutch ein und Google sagt "Meinten Sie: Deutsch"
Delphi-Quellcode:
Habe einen Code gefunden aber nicht in Delphi.
function GetSimilarWord(meinwort: string): string;
begin end; Wie kann ich das übersetzen?
Code:
=begin
Raimbo, the Ruby AIM Bot Object. Copyright (C) 2003 Kurt M. Dresner (kdresner@rubyforge.org) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA =end require 'net/http' require 'uri/common' require 'cgi' Net::HTTP.version_1_2 module Google def Google.search(inputterms, numresults=1) unless inputterms.length > 0 return "What should I search for?" end searchterms = URI.escape inputterms query = "/search?q=#{searchterms}&btnG=Google+Search" result = "no results found." proxy_host = nil proxy_port = nil if(ENV['http_proxy']) if(ENV['http_proxy'] =~ /^http:\/\/(.+):(\d+)$/) proxy_host = $1 proxy_port = $2 end end http = Net::HTTP.new("www.google.com", 80, proxy_host, proxy_port) http.start do |http| begin resp , = http.get(query) if resp.code.to_i == 200 didyoumean = nil results = [] resp.body.each("Similar pages</a>") do |l| if not didyoumean and l =~ /Did you mean:.*?[i](.*?)<\/i>.*?<\/a>/ didyoumean = $1 end if (l =~ /(<p class="?g"?>)(<a.*?<\/a>)/) and (results.size < numresults) results.push("Hit #{results.size + 1}: #{$2}") end end unless results.empty? result = results.join("\n") if (results.size < numresults) and didyoumean result += " (Did you mean [i]#{didyoumean}[/i]?)." else result += "." end # comment out the line below to leave the search terms bolded result.gsub!(/[b]|<\/b>/, "") else if didyoumean result += "\n(Did you mean [i]#{didyoumean}[/i]?)." end end end rescue => e result = "Error encountered while talking to Google." end end CGI.unescapeHTML result end end |
Re: Google Meinten Sie
also diese funktion macht nichts anderes als das der Funktion übergebene Wort an Google zu schicken und zu schauen ob Google ein "did you mean..." vorschlägt und das zurückzugeben - das ist ja nicht wirklich eine glanzleistung :?
Ich weis nicht ob dir das bewusst ist - wenn ja: IdHTTP, und dann einfach was du zurückbekommst auswerten, dürfte nicht sooo schwer sein. Wenn nein - und das hoffe ich ;) - kann ich dir aber da jetzt leider auch keinen Algo anbieten :( |
Re: Google Meinten Sie
Tja, lies dir ein C++ Tutorial durch.
Oder, noch ne Idee, du überprüfst SoundEx Werte, und zwar die vom eingegebenen Wort mit Wörtern in einer Datenbank, wobei die Wörter in der Datenbank, die öfter eingegeben werden, Vorrang haben.
Delphi-Quellcode:
type
TWord = record text: String; count: Integer; end; var Words: array of TWord; //... function GetSimilar(str: String): String; var I: Integer; bestindex, bestcount: Integer; begin bestcount:=0; bestindex:=-1; for I:=0 to high(Words) do if (soundexsimilar(str, words[I].text)) and (words[I].count>bestcount) then begin bestcount:=words[I].count; bestindex:=I; end; if bestindex=-1 then result:='' else result:=words[bestindex].text; end; |
Re: Google Meinten Sie
Zitat:
...:cat:... |
Re: Google Meinten Sie
Du brauchst einen Algorithmus der die die Ähnlichkeit von 2 Wörtern berechnet. Wie z.B. Levenshtein.
|
Re: Google Meinten Sie
Zitat:
...:cat:... |
Re: Google Meinten Sie
Zitat:
Wie kann man den User-Agent ändern? Braucht es da einen Registry Eingriff? |
Re: Google Meinten Sie
Hi!
Nein, dazu gibt es im OI (bei ausgewählter IdHttp-Komponente) die Eigenschaft Request und dort drunter User-Agent! Ciao, Frederic |
Re: Google Meinten Sie
ok, schon gefunden
Delphi-Quellcode:
TIdHttp.Request.UserAgent
|
Re: Google Meinten Sie
Zitat:
|
Alle Zeitangaben in WEZ +1. Es ist jetzt 10:16 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz