Frequent Subtree Mining Algorithm

Only available on StudyMode
  • Topic: ASCII
  • Pages : 6 (488 words )
  • Download(s) : 133
  • Published : March 2, 2013
Open Document
Text Preview
// FREQUENT SUBTREE MINING ALGORITHM...

#include
#include
#include
#include
#include
#include

using namespace std;

FILE *fp;
int no_of_nodes=0, string_ctr=0, vect_ctr=0, vect_ctr1=0,pos_ctr=0,*pos;

struct MyNode
{
string name;
vector children;
}*myroot, *myroot1, **tree_pattern, **subtree_pattern;

//FUNCTION PROTOTYPES DECLARATION ...
static void print_element_names(xmlNode *);
static MyNode* preprocess(xmlNode *,MyNode *, int);
int printMyNode(MyNode *);
void print(MyNode **, int);
void print_pos_array(int *,int);
int check_child(MyNode *, MyNode *);

int main()
{
xmlDoc *doc = NULL;
xmlDoc *doc1 = NULL;
xmlNode *root_element = NULL;
xmlNode *root_element1 = NULL;
const char *pattern = "/home/naveen/Desktop/SubTrees_in_Tree/Programs/pattern.xml"; const char *subpattern = "/home/naveen/Desktop/SubTrees_in_Tree/Programs/subpattern.xml";

doc = xmlReadFile(pattern, NULL, 0);
doc1 = xmlReadFile(subpattern, NULL, 0);

if (doc == NULL || doc1 == NULL)
printf("error: could not parse file %s or %s.\n", pattern,subpattern); else
{
fp = fopen("input_file.txt","w");

// For Getting The Root Element Node ...
root_element = xmlDocGetRootElement(doc);
print_element_names(root_element);
printf("The Total Number Of Nodes In The Tree : %d \n",no_of_nodes); fprintf(fp,"\n");

tree_pattern = (struct MyNode **)malloc(no_of_nodes*sizeof(struct MyNode *)); pos = (int *)malloc(no_of_nodes*sizeof(int));

no_of_nodes = 0;
root_element1 = xmlDocGetRootElement(doc1);
print_element_names(root_element1);
printf("The Total Number Of Nodes In The SubTree : %d\n",no_of_nodes);

int n = no_of_nodes;
subtree_pattern = (struct MyNode **)malloc(no_of_nodes*sizeof(struct MyNode *)); no_of_nodes = 0;
myroot = new MyNode(); myroot1 = new MyNode();
preprocess(root_element,myroot,0);
preprocess(root_element1,myroot1,1);

fprintf(fp,"\n\n Tree : ");
printMyNode(myroot);
fprintf(fp,"\n Sub Tree : ");
printMyNode(myroot1);

printf("\n Tree : "); print(tree_pattern,vect_ctr); printf("\n SubTree : "); print(subtree_pattern,vect_ctr1);

for(int k=0;kname.c_str()),(char *)
(subtree_pattern[0]->name.c_str()))) if(check_child(tree_pattern[k],subtree_pattern[0]))
pos[pos_ctr++] = k;

print_pos_array(pos,pos_ctr);
fprintf(fp,"\n");
for(int i=0;iname.c_str());
vector vect =node->children;

for(int i=0;iname.c_str());

fprintf(fp,"\n");
for(int i=0;inext)
{
MyNode *p = new MyNode();
if (cur_node->type == XML_ELEMENT_NODE)
{
p->name = (char *)cur_node->name ;
parent->children.push_back(p);

if(!flag)
tree_pattern[vect_ctr++] = p;
else
subtree_pattern[vect_ctr1++] = p;
++no_of_nodes;
}

preprocess(cur_node->children,p,flag);
}
}

// Recursive function for printing the XML structure ....
static void print_element_names(xmlNode * a_node)
{
xmlNode *cur_node = NULL;
int counter = 0, flag = 0;
for (cur_node = a_node; cur_node; cur_node = cur_node->next) {
if (cur_node->type == XML_ELEMENT_NODE)
{
printf("%d %s \n", ++counter, cur_node->name); ++no_of_nodes; flag = 1;

fprintf(fp,"%s ",(char *)cur_node->name); }

if((cur_node->children == NULL) && (flag == 1))
fprintf(fp,"-1 ");...
tracking img