/* * Функция нахождения совпадений введенного текста со всеми экстремисткими фразами и словами из словаря * и оценки вероятности экстремистского характера текста на основании их присутствия. * vocabulary - словарь экстремистских слов и фраз. * indexSpacesOfStartPhrases - индексы пробелов перед экстремистскими фразами в тексте. * indexSpacesOfEndPhrases - индексы пробелов после экстремистских фраз в тексте. * probabilityExtremistPhrases - массив значений вероятности присутствия фраз или слов того или иного * вида экстремизма в тексте, в %. */ public AvailabilityExtremistPhrasesResult AvailabilityExtremistPhrases(ExtremistPhraseVocabulary vocabulary) { string[] enterTextWords = enterText.TextWords(); List <int> indexSpacesOfStartPhrases; List <int> indexSpacesOfEndPhrases; int[] occurenceExtremistPhrases = OccurenceCountExtremistPhrases(vocabulary, enterTextWords, out indexSpacesOfStartPhrases, out indexSpacesOfEndPhrases); double[] probabilityExtremistPhrases = ProbabilityExtremistPhrases(occurenceExtremistPhrases); return(new AvailabilityExtremistPhrasesResult(probabilityExtremistPhrases, indexSpacesOfStartPhrases, indexSpacesOfEndPhrases)); }
/* * Функция расчета количества встречавшихся экстремистских фраз и выражений * по их виду экстремизма. * vocabulary - словарь экстремистских фраз и слов. * textWords - исходный текст в виде массива слов. * occurenceExtremistPhrases - массив частот встречающихся экстремистских фраз и слов * в тексте. * indexSpacesOfStartPhrases - индексы пробелов перед экстремистскими фразами в тексте. * indexSpacesOfEndPhrases - индексы пробелов после экстремистских фраз в тексте. */ private int[] OccurenceCountExtremistPhrases(ExtremistPhraseVocabulary vocabulary, string[] textWords, out List <int> indexSpacesOfStartPhrases, out List <int> indexSpacesOfEndPhrases) { List <string> extremistTypes = vocabulary.ExtremistTypes(); int[] occurenceExtremistPhrases = new int[extremistTypes.Count]; indexSpacesOfStartPhrases = new List <int>(); indexSpacesOfEndPhrases = new List <int>(); foreach (ExtremistPhrase extremistPhrase in vocabulary.phrases) { string[] phraseWords = extremistPhrase.PhraseWords(); for (int wordIndex = 0; wordIndex < textWords.Length; wordIndex++) { if (WordCoincidence(textWords[wordIndex], phraseWords[0])) { int availability = 1; if (textWords.Length - wordIndex >= phraseWords.Length) { for (int phraseWordIndex = 1; phraseWordIndex < phraseWords.Length; phraseWordIndex++) { if (WordCoincidence(textWords[wordIndex + phraseWordIndex], phraseWords[phraseWordIndex])) { availability++; } else { break; } } if (availability == phraseWords.Length) { occurenceExtremistPhrases[extremistTypes.IndexOf(extremistPhrase.typePhrase)]++; indexSpacesOfStartPhrases.Add(enterText.SpaceElementLocationTextIndex(wordIndex)); indexSpacesOfEndPhrases.Add(enterText.SpaceElementLocationTextIndex(wordIndex + phraseWords.Length)); } } wordIndex += availability - 1; } } } return(occurenceExtremistPhrases); }
public FormAnalizeText() { InitializeComponent(); textVocabulary = new ExtremistTextVocabulary(); phraseVocabulary = new ExtremistPhraseVocabulary(); }