<commit_before>/**
 *
 * APDPlat - Application Product Development Platform Copyright (c) 2013, 杨尚川,
 * <EMAIL>
 *
 * 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, either version 3 of the License, or (at your option) any later
 * version.
 *
 * 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, see <http://www.gnu.org/licenses/>.
 *
 */
package org.apdplat.superword.rule;

import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;

import org.apdplat.superword.model.Suffix;
import org.apdplat.superword.model.Word;
import org.apdplat.superword.tools.SuffixExtractor;
import org.apdplat.superword.tools.WordSources;

/**
 * 从指定的英文单词的集合中找出符合后缀规则的单词
 * @author 杨尚川
 */
public class SuffixRule{
        private SuffixRule(){}

        public static TreeMap<Suffix, List<Word>> findBySuffix(Collection<Word> words, Collection<Suffix> suffixes) {
            TreeMap<Suffix, List<Word>> map = new TreeMap<>();
            for(Suffix suffix : suffixes){
                map.put(suffix, findBySuffix(words, suffix));
            }
            return map;
        }

        public static List<Word> findBySuffix(Collection<Word> words, Suffix suffix) {
            return words
                    .parallelStream()
                    .filter(word -> {
                        String w = word.getWord();
                        boolean hit = false;
                        String[] ps = suffix.getSuffix().toLowerCase().split(",");
                        for (String p : ps) {
                            p = p.replaceAll("-", "").replaceAll("\\s+", "");
                            if (w.toLowerCase().endsWith(p)
                                    && words.contains(new Word(w.substring(0, w.length()-p.length()).toLowerCase(),null))) {
                                hit = true;
                                break;
                            }
                        }<commit_msg>格式化为多行便于阅读<commit_after>/**
 *
 * APDPlat - Application Product Development Platform Copyright (c) 2013, 杨尚川,
 * <EMAIL>
 *
 * 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, either version 3 of the License, or (at your option) any later
 * version.
 *
 * 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, see <http://www.gnu.org/licenses/>.
 *
 */
package org.apdplat.superword.rule;

import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;

import org.apdplat.superword.model.Suffix;
import org.apdplat.superword.model.Word;
import org.apdplat.superword.tools.SuffixExtractor;
import org.apdplat.superword.tools.WordSources;

/**
 * 从指定的英文单词的集合中找出符合后缀规则的单词
 * @author 杨尚川
 */
public class SuffixRule{
        private SuffixRule(){}

        public static TreeMap<Suffix, List<Word>> findBySuffix(Collection<Word> words, Collection<Suffix> suffixes) {
            TreeMap<Suffix, List<Word>> map = new TreeMap<>();
            for(Suffix suffix : suffixes){
                map.put(suffix, findBySuffix(words, suffix));
            }
            return map;
        }

        public static List<Word> findBySuffix(Collection<Word> words, Suffix suffix) {
            return words
                    .parallelStream()
                    .filter(word -> {
                        String w = word.getWord();
                        boolean hit = false;
                        String[] ps = suffix.getSuffix().toLowerCase().split(",");
                        for (String p : ps) {
                            p = p.replaceAll("-", "").replaceAll("\\s+", "");
                            if (w.toLowerCase().endsWith(p)
                                    && words.contains(
                                        new Word(
                                                w.substring(0, w.length()-p.length()).toLowerCase(), null))) {
                                hit = true;
                                break;
                            }
                        }
{'fraction_non_alphanumeric': 0.1027202598457166, 'fraction_numerical': 0.00243605359317905, 'mean_word_length': 1.9609375, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6033965', 'n_tokens_mistral': 1340, 'n_tokens_neox': 1349, 'n_words': 391}