how can i build a formal context table based on data that i get from a text file using c#? i can just browse the location of the data but dunno how to create a table of formal context based on that data. below are the data:

1 5
1
1 4
1
1 3 4 5
1 2 3 4 5
1 2 3 4 5
1 3 5
1 4
1 4 5
1 4 5
1 4
3 4
1 3 4 5
1 3 5
1 3 4 5
1 3 4 5
1 2 3 4 5
1 3 4 5
1 3 4 5
1 3 4 5
1 3 4 5
1 5
1
1 4 5
4
1 4 5
1 3 4 5
1 3 4 5
1 4

Recommended Answers

All 6 Replies

How are you supposed to be anylizing this data? A formal conecpt analysis requires some parameters (are you looking for even, odds, primes, and squares?) Do you have a tree-like class structure made to hold this data, or is this what you are having troubles creating?

i think so..i really stuck at this thing

Hi Celop,

Take a look at the project I attached to this post, it should get you in the right direction.

First, I created a lattice object class that had a list of integers and two properties for even or odd:

using System.Collections.Generic;

namespace ReadDataFromFile
{
    public class LatticeObject
    {
        private List<int> _integers = new List<int>();

        public LatticeObject(List<int> integers)
        {
            foreach (var i in integers)
            {
                _integers.Add(i);
            }
        }

        public List<int> Integers
        {
            get { return _integers; }
        }

        public bool Odd
        {
            get
            {
                foreach (var i in _integers)
                {
                    if (i % 2 == 0)
                    {
                        return false;
                    }
                }
                return true;
            }
        }

        public bool Even
        {
            get
            {
                foreach (var i in _integers)
                {
                    if (i % 2 == 1)
                    {
                        return false;
                    }
                }
                return true;
            }
        }
    }
}

Then, I created a loader that would return a list of lattice objects based on the data file you provided:

using System;
using System.Collections.Generic;
using System.IO;

namespace ReadDataFromFile
{
    public class LatticeLoader
    {
        public static List<LatticeObject> GetLatticeObjectFromFile(string path)
        {
            if (!File.Exists(path))
            {
                return null;
            }

            var listOfLatticeObjects = new List<LatticeObject>();

            using (var reader = new StreamReader(path))
            {
                while (true)
                {
                    var line = reader.ReadLine();

                    if (line == null)
                    {
                        break;
                    }

                    var intsAsStrings = line.Split(' '); // assuming space is the delimiter

                    var listOfInts = new List<int>();

                    foreach (var intAsString in intsAsStrings)
                    {
                        int newInt;

                        if (!Int32.TryParse(intAsString, out newInt))
                        {
                            return null;
                        }

                        listOfInts.Add(newInt);
                    }

                    listOfLatticeObjects.Add(new LatticeObject(listOfInts));
                }
            }

            return listOfLatticeObjects;
        }
    }
}

Then, I just made a quick console application to get the list and display some properties of the objects.

Hope this helps.

-Pat S.

thanks bro..really appreciate

I would go for a Dictionary<Tkey, Kvalue>, where Tkey will be row index, and Kvalue will be a List<T (and T in a list will be an integer>.
Of course, all this will be done when reading a file, row by row:

    using System.IO;

    private void buttonGetData(object sender, EventArgs e)
    {
        string filePath = @C:\Myfolder\Myfile.txt";
        Dictionary<int, List<int>> dic = GetDataFromFile(filePath);
        //show:
        StringBuilder sb = new StringBuilder();
        foreach(KeyValuePair<int, List<int>> kvp in dic)
        {            
             sb.Append(stirng.Format("line {0}, Items: ", kvp.Key));
             foreach(int item in kvp.Values)
                 sb.Append(string.Format("{0}, ", item);
             sb.AppendLine();
        }
    }

    private GetDataFromFile(string filePath)
    {
        Dictionary<int, List<int>> dic = new Dictionary<int, List<int>>();
        int counter = 1;           
        foreach(string item in ReadingFile(filePath)
        {
            string[] data = item.Split(' ');
            dic.Add(counter, new List<int>());
            foreach(string item in data)
                 dic[counter] = int.Parse(item);
             counter++;
        }
    }

    private IEnumeravble<string> ReadingFile(string filePath)
    {
        using(StreamReader st = new StreamReader(filePath))
        {
            string line;
            while((line = sr.ReadLine()) != null)
            {
                yiled return line;
            }
        }
    }

hello..i'm really appreciate of what both of u did to help me..but this is my real problem. i'm trying to build fca tool and until today i only can browse the data, load the data n show it on space. i try to build a context table based on the data after clicking button 'context'.

then, based on the table, the tool will produce a lattice tree after click button 'lattice'..in the folder i attached below, i provide my project..together with the data and example of table that i trying to buil. hope all of u can help me..thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.