0

メッセージにフレーズが含まれていることを確認するクラスがありMatcherます。PatternString.contains()

クラスは次のとおりです。

public class MotsClesFilter implements EmailFilter {

    final String NAME = "Filtrage par mots cles";
    /*private Pattern chaineSpam;
    private Matcher chaineCourriel;*/
    private int nbOccMotSpam;
    private byte confidenceLevel;
    @Override
    public String getFilterName() {
        return this.NAME;

    }

    @Override
    public byte checkSpam(MimeMessage message) {
        analyze(message);

        if(this.nbOccMotSpam==0)
            this.confidenceLevel = 1;
        else if (this.nbOccMotSpam>0 && this.nbOccMotSpam<2)
            this.confidenceLevel = CANT_SAY;
        else if (this.nbOccMotSpam>1 && this.nbOccMotSpam<3)
            this.confidenceLevel = 50;
        else if (this.nbOccMotSpam>3 && this.nbOccMotSpam<4)
            this.confidenceLevel = 65;
        else if (this.nbOccMotSpam>4 && this.nbOccMotSpam<5)
            this.confidenceLevel = 85;
        else this.confidenceLevel = 90;
        return (getConfidenceLevel());
    }


    public void analyze(MimeMessage message){
        try {
            List<String> listeChaines = new ArrayList<String>(); 
            BufferedReader bis = new BufferedReader(new InputStreamReader(new FileInputStream(new File("SpamWords.txt"))));
            while(bis.ready()){
                String ligne = bis.readLine();
                listeChaines.add(ligne);
            }

            String mail = ((String.valueOf(message.getContent())));
            //System.out.println(mail);


            for (int j =0; j<listeChaines.size();j++){
                //System.out.println(listeChaines.get(j));
                Pattern chaineSpam = Pattern.compile(listeChaines.get(j),Pattern.CASE_INSENSITIVE);
                Matcher chaineCourriel = chaineSpam.matcher(mail);
                if (chaineCourriel.matches())
                    this.nbOccMotSpam++;

            }

        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (MessagingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    @Override
    public byte getConfidenceLevel() {
        // TODO Auto-generated method stub
        return this.confidenceLevel;
    }

    @Override
    public boolean enabled() {
        // TODO Auto-generated method stub
        return true;
    }
}

によって返される結果は、checkSpammatches を使用する場合は常に 1 で、find を使用する場合は 90mail.contains(listeChaines.get(j))です。

4

1 に答える 1

0

つまり、メッセージはファイル内の文字列のいずれにも一致しませんが、ファイル内に少なくとも 5 つの文字列があり、メッセージで見つけることができます。

matches()文字列全体がパターンに一致するかどうかを確認します。一部の部分文字列が一致する場合はそうではありません。

于 2013-04-08T21:21:37.263 に答える