Skip to content

Commit

Permalink
Add sample for looking at phrase mentions
Browse files Browse the repository at this point in the history
  • Loading branch information
kant2002 committed Nov 18, 2024
1 parent 88f79da commit 1903264
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion TelegramExportProcessor.Sample/Program.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using TelegramExportProcessor;

var exportFile = args[0];
var chatHistory = await ExportParser.ParseChatExportFile(exportFile);
var chatHistory = await ExportParser.ParseChatExportFileAsync(exportFile);
if (chatHistory is null)
{
Console.WriteLine($"Cannot parse file {exportFile}");
Expand All @@ -13,6 +13,7 @@
PrintEntityTypes(messages);
FindAllLinks(messages);
FindTgChannels(messages);
FindMentions(messages, "із рук");
void FindAllLinks(IEnumerable<ChatMessage> entities)
{
foreach (var entryType in messages.SelectMany(_ => _.TextEntities.Where(_ => _.Type is "link" or "text_link").Select(_ => _.Href ?? _.Text)).Distinct())
Expand All @@ -33,6 +34,20 @@ void FindTgChannels(IEnumerable<ChatMessage> entities)
}
}

string FormatMessage(ChatMessage message)
{
return string.Join("", message.TextEntities.Select(_ => _.Text));
}

void FindMentions(IEnumerable<ChatMessage> entities, string searchString)
{
foreach (var foundMessage in messages.Where(_ => _.TextEntities.Any(_ => _.Text.Contains(searchString))))
{
Console.WriteLine(FormatMessage(foundMessage));
Console.WriteLine("===========================================================");
}
}

void PrintEntityTypes(IEnumerable<ChatMessage> entities)
{
Console.WriteLine($"Messages parsed : {messages.Count}");
Expand Down

0 comments on commit 1903264

Please sign in to comment.