Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
2429 connectés 

  FORUM HardWare.fr
  Programmation
  Java

  Aide moteur de recherche en Java

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

Aide moteur de recherche en Java

n°2056443
billouxs
Posté le 13-02-2011 à 17:02:40  profilanswer
 

Bonjour,
j'espere avoir poster dans la bonne section !
Donc voila je dois réaliser un mini moteur de recherche avec un dictionnaire ,j'arrive a placer les liens avec les mots clefs dans le dictionnaire mais je n'arrive pas a rechercher le lien par rapport aux mots clefs ,voici mon code :  
 
 
 
 

Code :
  1. package projet;
  2.  
  3. import java.io.IOException;
  4. import java.io.InputStreamReader;
  5. import java.io.Reader;
  6. import java.net.URL;
  7. import java.net.URLConnection;
  8. import java.util.ArrayList;
  9. import java.util.HashMap;
  10. import java.util.StringTokenizer;
  11. import javax.swing.text.BadLocationException;
  12. import javax.swing.text.EditorKit;
  13. import javax.swing.text.SimpleAttributeSet;
  14. import javax.swing.text.html.HTML;
  15. import javax.swing.text.html.HTMLDocument;
  16. import javax.swing.text.html.HTMLEditorKit;
  17.  
  18. public class robot {
  19. @SuppressWarnings("unchecked" )
  20. HashMap<String, ArrayList> Index ;
  21. @SuppressWarnings("unchecked" )
  22. public robot () {
  23. Index = new HashMap<String, ArrayList> ();
  24. }
  25. @SuppressWarnings("unchecked" )
  26. public HashMap<String, ArrayList> Link(String adresse) throws IOException, BadLocationException{
  27. //Charger la page
  28. URL url = new URL(adresse);
  29. URLConnection uconnection = url.openConnection();
  30. Reader rd = new InputStreamReader(uconnection.getInputStream());
  31. //lire le document HTML
  32. HTMLDocument doc = (HTMLDocument) kit.createDefaultDocument();
  33. doc.putProperty("IgnoreCharsetDirective", new Boolean(true));
  34. kit.read(rd, doc, 0);
  35. //Parcourir la balise lien
  36. HTMLDocument.Iterator it = doc.getIterator(HTML.Tag.A);
  37. while (it.isValid()) {
  38. SimpleAttributeSet s = (SimpleAttributeSet) it.getAttributes();
  39. String link = (String) s.getAttribute(HTML.Attribute.HREF);
  40. if (link != null && link.startsWith("http" ) && link.endsWith(".html" )) {
  41. String Nom=(String) s.getAttribute(HTML.Attribute.TITLE);
  42. //découpage des mots du titre du lien corespondant
  43. if(Nom!=null){
  44. StringTokenizer tmp = new StringTokenizer (Nom," " );
  45. ArrayList<String> tmp2 = new ArrayList<String> () ;
  46.  
  47. while (tmp.hasMoreTokens()){
  48. String tmp3=tmp.nextToken();
  49. if(tmp3.length()>2)
  50. tmp2.add(tmp3);
  51.  
  52. }
  53. Index.put(link, tmp2);
  54. }
  55. }
  56. it.next();
  57. }
  58. return Index;
  59. }
  60.  
  61. }


Merci d'avance et bonne journée a tous !!!!

Message cité 1 fois
Message édité par gilou le 25-03-2011 à 13:34:29
mood
Publicité
Posté le 13-02-2011 à 17:02:40  profilanswer
 

n°2056971
billouxs
Posté le 15-02-2011 à 13:54:48  profilanswer
 

aucune réponse :( :( :(

n°2056989
rufo
Pas me confondre avec Lycos!
Posté le 15-02-2011 à 14:58:24  profilanswer
 

Commences par nous dire plus précisément ce qui ne marche pas. Perso, je suis déjà pas sûr d'avoir compris ton pb :/


---------------
Astres, outil de help-desk GPL : http://sourceforge.net/projects/astres, ICARE, gestion de conf : http://sourceforge.net/projects/icare, Outil Planeta Calandreta : https://framalibre.org/content/planeta-calandreta
n°2056995
zapan666
Tout est relatif
Posté le 15-02-2011 à 15:09:48  profilanswer
 

billouxs a écrit :

Bonjour,
j'espere avoir poster dans la bonne section !
Donc voila je dois réaliser un mini moteur de recherche avec un dictionnaire ,j'arrive a placer les liens avec les mots clefs dans le dictionnaire mais je n'arrive pas a rechercher le lien par rapport aux mots clefs ,voici mon code :  


Tu peux parcourir les ensembles clé/valeurs via la méthode entrySet d'une Map
http://download.oracle.com/javase/ [...] ySet%28%29
 

Code :
  1. String findLink(String myTag) {
  2.         for (Map.Entry<String, ArrayList> entry : Index.entrySet()) {
  3.              if(entry.getValue().contrains(myTag)) {
  4.                    return entry.getKey();
  5.              } 
  6.        }
  7. }



---------------
my flick r - Just Tab it !
n°2062050
billouxs
Posté le 09-03-2011 à 14:59:32  profilanswer
 

Merci pour ta réponse !!!
Par contre la je voudrai parcourir récursivement sur N niveaux ,la page internet donnée en initialisation du programme !
Quelqu'un aurait une idée svp ?


Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  Java

  Aide moteur de recherche en Java

 

Sujets relatifs
recherche editeur avec aide a la saisie style dreamweaverRecherche le titre d'un bouquin C++
Validation XML en Java - Problème de namespaceMacro Excel recherche fichiers et copie [RESOLU]
Programmation en C, besoin d'aide[Algo] recherche, trie et renommage de fichiers
Recherche d'une liste de valeurs dans une autreComment inclure ma bbd postgresql avec application java dans un jar ?
Recherche module commandes groupées 
Plus de sujets relatifs à : Aide moteur de recherche en Java


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR