水曜日, 2月 25, 2015

Java: データ・マイニング ECLAT変換

データ・マイニングなんぞでデータ変換など需要がありましたので、プログラムなど置いておきます。

変換といっても縦のものを横にするという種類のもので、こんな感じです。


 アルファベットが項目で、数字がIDです。

走らせるとアルファベットからIDを列挙します。

import java.util.*;
// Equivalence Class Transformation
public class ECLAT
{
public static void main(String args[])
{
HashMap<Integer, byte[]> hash=new HashMap<>();
hash.put(10,new String("acde").getBytes());
hash.put(20,new String("abe").getBytes());
hash.put(30,new String("bce").getBytes());
Set<Integer> keys=hash.keySet();
TreeSet<Integer> sortedKeys=new TreeSet<>();
TreeSet<Character> itemset=new TreeSet<>();
for(Integer key: keys)
{
sortedKeys.add(key);
}
for(Integer key: sortedKeys)
{
System.out.print(key+" | ");
byte[] buf=hash.get(key);
for(int i=0;i<buf.length;i++)
{
itemset.add((char)buf[i]);
System.out.print((char)buf[i]);
if(i<buf.length-1)
System.out.print(",");
}
System.out.println();
}
System.out.println();
for(Character ch: itemset)
{
System.out.print(ch+" | ");
for(Integer key: sortedKeys)
{
byte[] buf=hash.get(key);
int i=0;
while(buf[i]!=ch && ++i<buf.length){}
if(i<buf.length)
{
System.out.print(key+", ");
}
}
System.out.println();
}
}
}
view raw ECLAT.java hosted with ❤ by GitHub

Qt: 外部プログラムを起動する

  Qt/C++ のアプリは、外部へ直接アクセスできます。これはネットアプリでは不可能な Qt のメリットです。 外部プログラムを起動することもできます。QProcess::startDetached() を使うと独立したプロセスを立ち上げることができます。 この QProces...