FORUM Tom's Hardware » Programmation » C / C++ / Java » [Java] Aide pour le démarrage d'un programme
 

[Java] Aide pour le démarrage d'un programme

Overclocking & Tuning : fifi2191 et 79 utilisateurs inconnus

 Mot :   Pseudo :  
 
Bas de page
Auteur
 Sujet : [Java] Aide pour le démarrage d'un programme
 
Plus d'informations

Bonjour,
 
j'aurais besoin d'aide pour commencer mon projet
En espérant que vous puissiez m'apporter une aide.
 
PS :les interfaces imposées sont jointes au message
 
Merci par avance

Citation :


Description du Projet
 
Le programme Foogle (foo-google) est un programme qui crée un index à partir d'un fichier et qui permet de faire des requètes de recherche de mots en utilisant les opérateurs ET et OU pour trouver l'ensemble des lignes satisfaisant la requète.
 
 
Ligne de Commande du Logiciel
 
Le logiciel doit se présenter sous la forme d'un jar exécutable.
La ligne de commande permet de créer l'index ou d'effectuer des requètes sur un
index déjà crée
java -jar foogle.jar [index|query] [option spécifique dépendant de index ou query]
index :
java -jar foogle.jar index [-strategy name] [-minlength length]fichier.ext
 crée un index à partir d'un fichier.ext, le nom du fichier sera fichier.ext.idx
 -minlength indique le nombre de lettre minimum du mot pour qu'il appartienne
 à l'index.
 -strategy permet de spécifier une stratégie de contexte par son nom.
 Le contexte correspond aux mots avant et après un mot recherché.
 (par défaut: none)
 
 La stratégie "none" indique que le contexte (la ligne ou une partie de la ligne n'est pas stockée dans l'index.
 La stratégie "near" indique que le contexte correspond au mot précédent ainsi qu'au mot suivant le mot courant.
 
 Exemple de résultat avec un contexte "near", avec le fichier :
 hello toto how are you ?
 well, i'm fine, well Dee fine.

 
 Pour la requète toto & how (les contextes sont agglomérés):
line 1: hello toto how are
 
 Pour la requète fine (le mots fine est présent plusieurs fois):
line 2: well fine well ... Dee fine
 
De façon optionnel vous pouvez ajouter un contexte intelligent.
 
query :
java -jar foogle.jar query [-n count] fichier.ext.idx expr
 effectue une requète expr sur l'index fichier.ext.idx et affiche l'ensemble
 des lignes satisfaisant la requète.
 -n permet de spécifier le nombre de résultat voulu.
 
 Les requètes sur l'index correspond à un arbre au format préfixé,
 exemple "& toto | titi @t?t?" est équivalent à l'arbre
 

               &
 toto                    |
                titi       @t?t?


 
 L'opérateur ET ('&') reporte la ligne uniquement si les deux mots
 appartiennent à la ligne.
 L'opérateur OU ('|') reporte la ligne si un des deux mots appartient
 à la ligne.
 L'opérateur @ permet d'indiquer une expression régulière (au format PERL) pour rechercher les mots.
 
 De façon optionnel, il est possible dans le cas des OU lorsque l'on fixe le
 nombre de résultat voulu de ne pas calculer l'ensemble de tous les résultats
 possibles. De plus, lors de requète concernant beaucoup de résultat possible, il est possible de manipuler des itérateurs plutôt que des listes pour éviter d'avoir de grosses structures de données intermédiaires.
 
 
Architecture du Logiciel
 
Pour vous aidez et nous permettre de tester automatiquement votre logiciel,
un ensemble d'interface est imposée, vous ne devez en aucun cas toucher leur code.
Exemples d'utilisation des interfaces :
Création d'un index :

Code :
  1. FoogleFacade foogle=new FoogleFacadeImpl();
  2. ContextStrategy contextStrategy=
  3.     foogle.getContextStrategyMap().get("none" );
  4. Index index=foogle.createIndex(
  5.     new File("bbe.txt" ),contextStrategy);
  6. foogle.saveIndex(index,new File("bbe.idx" ));


 
Recherche dans un index :

Code :
  1. Index index2=foogle.loadIndex(new File("bbe.idx" ));
  2. System.out.println("indexed filename:"+index2.getFilename());
  3. QueryFactory factory2=foogle.createQueryFactory(index2);
  4. Query query2=factory2.and(factory2.query("God" ),
  5.     factory2.query("solid" ));
  6. ContextStrategy contextStrategy2=index2.getContextStrategy();
  7. for(Result result2:query2.execute(10)) {
  8.     System.out.println("line:"+result2.getLine());
  9.     System.out.println("ctx:"+contextStrategy2.getContext(result2));
  10. }


Plus d'informations

Voici les différentes interfaces qui sont fournis avec l'énoncé

Code :
  1. import java.util.Collection;
  2. /** Represents a context strategy i.e. how to obtain a context
  3. *  of the indexed words.
  4. *   
  5. *  
  6. * @see FoogleFacade#getAllContextStrategies()
  7. * @see FoogleFacade#createIndex(ContextStrategy)
  8. */
  9. public interface ContextStrategy {
  10.   /** Retruns the name of the Strategy.
  11.    * @return the name of the current strategy.
  12.    */
  13.   public String getName();
  14.  
  15.   /** Returns the context of a result,
  16.    *  this result must be created by a query on an
  17.    *  index that use the current strategy.
  18.    *  
  19.    * @param result of a qery on an index that
  20.    *  used this strategy.
  21.    * @return an unmodifiable list of words representing
  22.    *  the context of the result.
  23.    *   
  24.    * @throws IllegalArgumentException if the result is not created
  25.    *  with an index using this strategy.
  26.    *   
  27.    *@see Index#getContextStrategy()
  28.    */
  29.   public Collection<? extends CharSequence> getContext(Result result);
  30. }
  31. import java.io.File;
  32. import java.io.IOException;
  33. import java.io.Reader;
  34. import java.util.Map;
  35. import java.util.regex.Pattern;
  36. /** Access point for creating, loading, saving foogle index and
  37. *  performs some queries on it.
  38. *  
  39. */
  40. public interface FoogleFacade {
  41.   /** Creates an in-memory index with a specified strategy
  42.    *  and appends all words extracted of a specific file.
  43.    * @param strategy the context strategy used to create the index.
  44.    * @param file all words of the file will be appended in the index.  
  45.    * @return a new in-memory index.
  46.    * @throws IOException if the file doesn't exists or is unreadable.
  47.    */
  48.   public Index createIndex(File file,ContextStrategy strategy) throws IOException;
  49.  
  50.   /** Creates an in-memory index with a specified strategy
  51.    *  and appends all words extracted of a specific file.
  52.    *  All words are appended with the line of the reader and the specifed filename.  
  53.    *   
  54.    *  Words are separated using the java whitespace rule
  55.    *  <code>\p{javaWhitespace}</code> (see {@link Pattern})
  56.    *  and word are indexed is its length is greater or equals to 3.  
  57.    *   
  58.    * @param strategy the context strategy used to create the index.
  59.    * @param filename filename used for all word from the reader.
  60.    * @param reader all words contained in the reader will be appended line by line
  61.    *  in the index.  
  62.    * @return a new in-memory index.
  63.    * @throws IOException if the file doesn't exists or is unreadable.
  64.    *  
  65.    */
  66.   public Index createIndex(String filename,Reader reader,ContextStrategy strategy) throws IOException;
  67.  
  68.   /** Creates an in-memory index with a specified strategy
  69.    *  and appends all words extracted of a specific file in the specified index.
  70.    *  All words are appended with the line of the reader and the specifed filename.  
  71.    * @param strategy the context strategy used to create the index.
  72.    * @param filename filename used for all word from the reader.
  73.    * @param reader all words contained in the reader will be appended line by line
  74.    *        in the index.  
  75.    * @param accepter specifies how to separate word in the reader and
  76.    *        which words are indexable.
  77.    * @return a new in-memory index.
  78.    * @throws IOException if the file doesn't exists or is unreadable.
  79.    *  
  80.    * @see  
  81.    */
  82.   public Index createIndex(String filename,Reader reader,WordAccepter accepter,ContextStrategy strategy) throws IOException;
  83.  
  84.   /** Loads an index stored in a file in memory.
  85.    * @param indexFile file that store the index.
  86.    * @return an in-memory index corresponding to the file.
  87.    * @throws IOException raised if there is input/output problems.
  88.    */
  89.   public Index loadIndex(File indexFile)  throws IOException;
  90.  
  91.   /** Saves an index in a spacific file.
  92.    * @param index the index to store.
  93.    * @param indexFile file that will store the index.
  94.    * @throws IOException raised if there is input/output problems.
  95.    */
  96.   public void saveIndex(Index index,File indexFile) throws IOException;
  97.  
  98.   /** Returns a query factory specific to an index.
  99.    * @param index the queries will be created on this index.
  100.    * @return a new query factory.
  101.    *  
  102.    * @see Query#execute(int)
  103.    */
  104.   public QueryFactory createQueryFactory(Index index);
  105.  
  106.   /** Returns all context strategies understood by the facade.
  107.    *  This method must returned at least the "none" context strategy.
  108.    * @return an unmodifiable map of context strategies associated
  109.    *  with their names.
  110.    */
  111.   public Map<String,? extends ContextStrategy> getContextStrategyMap(); 
  112. }
  113. /** Represents an index of Foogle.
  114. *  
  115. *  
  116. */
  117. public interface Index {
  118.   /** Returns the name of the indexed file.
  119.    * @return the name of the indexed file.
  120.    */
  121.   public String getFilename();
  122.  
  123.   /** Returns the context startegy used by the current index.
  124.    * @return the context strategy.
  125.    *  
  126.    * @see FoogleFacade#createIndex(ContextStrategy)
  127.    * @see FoogleFacade#getAllContextStrategies()
  128.    */
  129.   public ContextStrategy getContextStrategy();
  130. }
  131. /** Represents a query to an index.
  132. *  The query is specific to an index.
  133. *   
  134. *  
  135. * @see QueryFactory
  136. * @see FoogleFacade#createQueryFactory(Index)
  137. */
  138. public interface Query {
  139.   /** Query the index to find results corresponding to a
  140.    *  specific query.
  141.    *  
  142.    * @return the result of the query.
  143.    *  
  144.    * @see Query#execute(int)
  145.    */
  146.   public Iterable<? extends Result> execute();
  147.  
  148.   /** Query the index to find results corresponding to a
  149.    *  specific query.
  150.    *   
  151.    *  @param maxCount a positive integer  
  152.    *  
  153.    * @return the result of the query.
  154.    *  
  155.    * @see QueryFactory
  156.    * @see FoogleFacade#createQueryBuilder(String)
  157.    */
  158.   public Iterable<? extends Result> execute(int maxCount);
  159. }
  160. import java.util.regex.Pattern;
  161. /** Factory used to create index queries,
  162. *  The factory is specific to an index.
  163. *   
  164. *  All results returned by {@link Query#execute()}
  165. *  on these queries are garanteed to have distinct
  166. *  line numbers (see {@link Result#getLine()}).
  167. *
  168. */
  169. public interface QueryFactory {
  170.   /** Creates a query for a simple word.
  171.    *  
  172.    * @param word the queried word.
  173.    * @return a new query.
  174.    */
  175.   public Query query(CharSequence word);
  176.  
  177.   /** Creates a query for a regex.
  178.    *  
  179.    * @param pattern the queried regex.
  180.    * @return a new query.
  181.    */
  182.   public Query query(Pattern pattern);
  183.  
  184.   /** Create a new query by oring query1 and query2.
  185.    *   
  186.    * @param query1 the first query.
  187.    * @param query2 the second query.
  188.    * @return the new query.
  189.    */
  190.   public Query or(Query query1,Query query2);
  191.  
  192.   /** Create a new query by anding query1 and query2.
  193.    * @param query1 the first query.
  194.    * @param query2 the second query.
  195.    * @return the new query.
  196.    */
  197.   public Query and(Query query1,Query query2);
  198. }
  199. /** Result of a query, represents a location in a line of a file.
  200. *  
  201. *  A result can have a specific context value associated with it
  202. *  depending on the index strategy, use  
  203. *  {@link ContextStrategy#getContext(Result)} to obtain such context.
  204. *  
  205. *  
  206. * @see Index#executeQuery(Query)
  207. */
  208. public interface Result {
  209.   /** Returns the line number containing
  210.    *  the result
  211.    * @return a line number.
  212.    */
  213.   public int getLine();
  214. }
  215. import java.util.Scanner;
  216. import java.util.regex.Pattern;
  217. /** This interface specifies
  218. *  how words are delimited in a text
  219. *  using a regex pattern
  220. *  {@link #getDelimiterRegex()}
  221. *  and which word are indexed
  222. *  {@link #isIndexable(CharSequence)}.
  223. *  
  224. */
  225. public interface WordAccepter {
  226.   /** Returns the regex pattern used to separate words.
  227.    * @return a regex pattern.
  228.    *  
  229.    * @see Scanner#useDelimiter(Pattern)
  230.    */
  231.   public Pattern getDelimiterRegex();
  232.  
  233.   /** Indicates if a word should be indexed or not.
  234.    * @param word the word
  235.    * @return true if the word is indexable, false otherwise.
  236.    */
  237.   public boolean isIndexable(CharSequence word);
  238. }

Profil : Pointeur
Plus d'informations

non, on fait pas de résoltution d'exercice ici :o
 
commence toi meme (si on t'as donné cet exercice c'est que tu es censé avoir le niveau) et reviens si tu as des problèmes


---------------
Da Bidz Triad©®™: Bidz Interceptor
.:: Smileyz version 4.2 [050625]::. -- Code source disponible sous licence GPL.
[u

Aller à :
  FORUM Tom's Hardware » Programmation » C / C++ / Java » [Java] Aide pour le démarrage d'un programme
 

Annonces Google
Publicité