Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Text.RegularExpressions;
- using System.Xml;
- using System.Xml.Serialization;
- namespace FeedAnalyzer
- {
- [System.Serializable()]
- public class FeedItem
- {
- public string Title { get; set; }
- public string Sumary { get; set; }
- public DateTime Date { get; set; }
- public string Link { get; set; }
- public string Categories { get; set; }
- }
- class Program
- {
- static void Main(string[] args)
- {
- TwoWordAnalysis();
- Console.WriteLine("ok");
- Console.ReadKey();
- }
- static void TwoWordAnalysis()
- {
- List<FeedItem> list = LoadFeeds("data.xml");
- Console.WriteLine(list.Count + " loaded");
- StreamReader keywordsFile = new StreamReader("keywords.txt");
- StreamWriter output = new StreamWriter("output.txt");
- List<string> keywords = new List<string>();
- while (keywordsFile.EndOfStream == false)
- keywords.Add(keywordsFile.ReadLine());
- string[] keywordArray = keywords.ToArray();
- for (int x = 0; x < keywordArray.Length - 1; x++)
- {
- for (int y = x + 1; y < keywordArray.Length; y++)
- {
- int num = 0;
- Regex regex1 = new Regex(String.Join(String.Empty, "\\b", keywordArray[x], " ", keywordArray[y], "\\b"), RegexOptions.IgnoreCase);
- Regex regex2 = new Regex(String.Join(String.Empty, "\\b", keywordArray[y], " ", keywordArray[x], "\\b"), RegexOptions.IgnoreCase);
- foreach (FeedItem f in list)
- num += regex1.Matches(String.Join(" ", f.Title, f.Sumary)).Count + regex2.Matches(String.Join(" ", f.Title, f.Sumary)).Count;
- if (num > 0)
- {
- output.WriteLine(String.Join(" ", num, keywordArray[x], keywordArray[y]));
- }
- }
- }
- output.Close();
- }
- public static List<FeedItem> LoadFeeds(string fileName)
- {
- List<FeedItem> list = new List<FeedItem>();
- try
- {
- XmlReaderSettings settings = new XmlReaderSettings();
- settings.CheckCharacters = false;
- XmlSerializer s = new XmlSerializer(typeof(FeedItem[]));
- XmlReader reader = XmlReader.Create(new StreamReader(fileName), settings);
- FeedItem[] array = (FeedItem[])s.Deserialize(reader);
- list.AddRange(array);
- reader.Close();
- }
- catch (Exception exc)
- {
- Console.WriteLine(exc.Message);
- Console.WriteLine(exc.StackTrace);
- return null;
- }
- return list;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement