Help needed: glob pattern generator

  • 19 Replies
  • 5651 Views
*

frankinstien

  • Replicant
  • ********
  • 653
    • Knowledgeable Machines
Re: Help needed: glob pattern generator
« Reply #15 on: October 03, 2021, 08:18:29 pm »
I made modifications to force the code to only count a word once when checking within the same sentence.

*

frankinstien

  • Replicant
  • ********
  • 653
    • Knowledgeable Machines
Re: Help needed: glob pattern generator
« Reply #16 on: October 03, 2021, 11:03:12 pm »
I placed a sequence check so if not all sentences are in a somewhat similar sequence it will print no matches.

Code
using System;
using System.Collections.Generic;
using System.Linq;

public class Program
{
public static void Main()
{
List<string> alreadyCounted = new List<string>();
var counts = new Dictionary<string, Tally>();
string[] sets = new string[] { "so I have a car, but this car is used", "so I have a bicycle", "so you have a car", "so, I have a knife too" };
foreach (String aSet in sets)
{
var sentenceSplit = aSet.Split(new char[] { ' ', ',' });
alreadyCounted.Clear();
int pos = 0;
foreach (String aWord in sentenceSplit)
{
pos++;
var trimmed = aWord.Trim();
if (counts.ContainsKey(trimmed) && !alreadyCounted.Contains(trimmed))
{
counts[trimmed].Count = counts[trimmed].Count + 1;
counts[trimmed].Positions.Add(pos);
}
else if(!alreadyCounted.Contains(trimmed))
counts.Add(trimmed, new Tally(1, pos));
alreadyCounted.Add(trimmed);
}
}

var results = counts.Where(x => x.Value.Count == sets.Length);
if (results != null && CheckSequence(results.ToList()))
{
foreach (KeyValuePair<string, Tally> entry in results)
{
Console.Write(entry.Key + ": ");
foreach(int pos in entry.Value.Positions)
{
Console.Write(pos.ToString() + ",");
}
Console.WriteLine("");
}
}
else
Console.WriteLine("No matches that are sequentially similar.");
}

private static bool CheckSequence(List<KeyValuePair<string, Tally>> results)
        {
foreach (KeyValuePair<string, Tally> anEntry in results)
{
int temp = anEntry.Value.Positions[0];
for (int idx = 1; idx <anEntry.Value.Positions.Count; idx++)
                {
if (temp > anEntry.Value.Positions[idx])
{
return false;
}

temp = anEntry.Value.Positions[idx];

}
}

return true;
        }
}

sealed class Tally
{
public int Count {set; get;}
public List<int> Positions {set; get;}

public Tally(int count, int pos)
{
Count = count;
Positions = new List<int>();
Positions.Add(pos);
}
}

*

8pla.net

  • Trusty Member
  • ***********
  • Eve
  • *
  • 1307
  • TV News. Pub. UAL (PhD). Robitron Mod. LPC Judge.
    • 8pla.net
Re: Help needed: glob pattern generator
« Reply #17 on: October 05, 2021, 07:15:49 am »
I was thinking word frequency analysis...

Code
<?php
$inputs = <<<EOD
so I have a car
so I have a bicycle
so you have a car
EOD;
$table=array_count_values(str_word_count($inputs, 1));
foreach($table as $word=>$freq){
if($freq==3){
   $words[]=$word;
}
}
echo var_export($words,TRUE);
?>

array (
  0 => 'so',
  1 => 'have',
  2 => 'a',
)
My Very Enormous Monster Just Stopped Using Nine

*

Zero

  • Eve
  • ***********
  • 1287
Re: Help needed: glob pattern generator
« Reply #18 on: October 05, 2021, 10:17:08 pm »
Check this one:
Code: text
    "car I have a car, but this car is used",
    "so I have a car",
    "I so car have you"
Mine is wrong...
Getting:
Code: text
"* I* have *"
Expected:
Code: text
"*I * have *"

*

frankinstien

  • Replicant
  • ********
  • 653
    • Knowledgeable Machines
Re: Help needed: glob pattern generator
« Reply #19 on: October 06, 2021, 08:22:19 pm »
Check this one:
Code: text
    "car I have a car, but this car is used",
    "so I have a car",
    "I so car have you"
Mine is wrong...
Getting:
Code: text
"* I* have *"
Expected:
Code: text
"*I * have *"

Trim the text for each word parsed, that would remove the space. If you look at my code it does that and you could also modify it, easily, to sense the number of sentences with a pattern and list those with it and without it.

 


Requirements for functional equivalence to conscious processing?
by DaltonG (General AI Discussion)
November 19, 2024, 11:56:05 am
Will LLMs ever learn what is ... is?
by HS (Future of AI)
November 10, 2024, 06:28:10 pm
Who's the AI?
by frankinstien (Future of AI)
November 04, 2024, 05:45:05 am
Project Acuitas
by WriterOfMinds (General Project Discussion)
October 27, 2024, 09:17:10 pm
Ai improving AI
by infurl (AI Programming)
October 19, 2024, 03:43:29 am
Atronach's Eye
by WriterOfMinds (Home Made Robots)
October 13, 2024, 09:52:42 pm
Running local AI models
by spydaz (AI Programming)
October 07, 2024, 09:00:53 am
Hi IM BAA---AAACK!!
by MagnusWootton (Home Made Robots)
September 16, 2024, 09:49:10 pm
LLaMA2 Meta's chatbot released
by spydaz (AI News )
August 24, 2024, 02:58:36 pm
ollama and llama3
by spydaz (AI News )
August 24, 2024, 02:55:13 pm
AI controlled F-16, for real!
by frankinstien (AI News )
June 15, 2024, 05:40:28 am
Open AI GPT-4o - audio, vision, text combined reasoning
by MikeB (AI News )
May 14, 2024, 05:46:48 am
OpenAI Speech-to-Speech Reasoning Demo
by MikeB (AI News )
March 31, 2024, 01:00:53 pm
Say good-bye to GPUs...
by MikeB (AI News )
March 23, 2024, 09:23:52 am
Google Bard report
by ivan.moony (AI News )
February 14, 2024, 04:42:23 pm
Elon Musk's xAI Grok Chatbot
by MikeB (AI News )
December 11, 2023, 06:26:33 am

Users Online

363 Guests, 0 Users

Most Online Today: 491. Most Online Ever: 2369 (November 21, 2020, 04:08:13 pm)

Articles