Works a bit better.
This commit is contained in:
parent
947cf8385f
commit
11eb3306b9
|
@ -49,6 +49,7 @@ int godist_init() {
|
||||||
printf(" %d edges\n", link_count);
|
printf(" %d edges\n", link_count);
|
||||||
|
|
||||||
accumulate_evidence(get_bp());
|
accumulate_evidence(get_bp());
|
||||||
|
print_term(get_bp());
|
||||||
}
|
}
|
||||||
|
|
||||||
void godist_exit() {
|
void godist_exit() {
|
||||||
|
@ -83,6 +84,7 @@ int godist_read_term(FILE *fd) {
|
||||||
struct node *n = (struct node*) malloc(sizeof(struct node));
|
struct node *n = (struct node*) malloc(sizeof(struct node));
|
||||||
n->parentc = 0;
|
n->parentc = 0;
|
||||||
n->childrenc = 0;
|
n->childrenc = 0;
|
||||||
|
n->visited = 0;
|
||||||
for (i=0; i<12; i++) {
|
for (i=0; i<12; i++) {
|
||||||
n->evidence[i] = ev[i];
|
n->evidence[i] = ev[i];
|
||||||
n->acc_evidence[i] = 0;
|
n->acc_evidence[i] = 0;
|
||||||
|
@ -91,8 +93,13 @@ int godist_read_term(FILE *fd) {
|
||||||
|
|
||||||
/* add to hash table */
|
/* add to hash table */
|
||||||
e.key = n->term;
|
e.key = n->term;
|
||||||
|
e.data = (void*)n;
|
||||||
res = hsearch(e, ENTER);
|
res = hsearch(e, ENTER);
|
||||||
|
/* if (res);
|
||||||
|
printf("hash-insert: %s", ((struct node*)res->data)->term);
|
||||||
|
else
|
||||||
|
printf("hash-insert: error");
|
||||||
|
*/
|
||||||
term_array[term_array_size++] = n;
|
term_array[term_array_size++] = n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,6 +113,14 @@ float go_distance(char *term1, char *term2) {
|
||||||
|
|
||||||
void add_node(char *term, int parentc, struct node **parents) {
|
void add_node(char *term, int parentc, struct node **parents) {
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void clear_flags(struct node *n) {
|
||||||
|
int i;
|
||||||
|
for (i=0; i<n->childrenc; i++)
|
||||||
|
clear_flags(n->children[i]);
|
||||||
|
n->visited = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void add_link(char *parent_id, char *child_id) {
|
void add_link(char *parent_id, char *child_id) {
|
||||||
|
@ -135,30 +150,43 @@ void add_link(char *parent_id, char *child_id) {
|
||||||
printf("FIXME: increase child count");
|
printf("FIXME: increase child count");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
parent->children[parent->childrenc++] = child;
|
parent->children[parent->childrenc] = child;
|
||||||
child->parents[child->parentc++] = parent;
|
parent->childrenc++;
|
||||||
|
/* printf("adding %x as child of %x\n", child, parent);*/
|
||||||
|
child->parents[child->parentc] = parent;
|
||||||
|
child->parentc++;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct node *get_bp() {
|
struct node *get_bp() {
|
||||||
ENTRY e, *ep;
|
ENTRY e, *ep;
|
||||||
e.key = "GO:0008150";
|
e.key = "GO:0008150";
|
||||||
ep = hsearch(e, FIND);
|
ep = hsearch(e, FIND);
|
||||||
if (ep)
|
|
||||||
return ep;
|
if (ep) {
|
||||||
if (ep == ESRCH)
|
/* printf("BP is %x and %s\n", (int) ep->data, ep->key);
|
||||||
printf("ESRCH\n");
|
printf("%d\n", ((struct node*)ep->data)->childrenc );
|
||||||
if (ep == ESRCH)
|
printf("%s\n", ((struct node*)ep->data)->term);*/
|
||||||
printf("ENOMEM\n");
|
return ep->data;
|
||||||
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void accumulate_evidence(struct node *n) {
|
void accumulate_evidence(struct node *n) {
|
||||||
int i, j;
|
int i, j;
|
||||||
|
if (n->visited)
|
||||||
|
return;
|
||||||
|
|
||||||
|
for (i=0; i<12; i++)
|
||||||
|
n->acc_evidence[i] = n->evidence[i];
|
||||||
|
|
||||||
for (i=0; i<(n->childrenc); i++) {
|
for (i=0; i<(n->childrenc); i++) {
|
||||||
|
if (!n->children[i]->visited) {
|
||||||
accumulate_evidence(n->children[i]);
|
accumulate_evidence(n->children[i]);
|
||||||
for (j=0; j<12; j++)
|
for (j=0; j<12; j++)
|
||||||
n->evidence[j] += n->children[i]->evidence[j];
|
n->acc_evidence[j] += n->children[i]->acc_evidence[j];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
/* printf(".");*/
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_terms() {
|
void print_terms() {
|
||||||
|
@ -168,3 +196,18 @@ void print_terms() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void print_term(struct node *n) {
|
||||||
|
int i;
|
||||||
|
printf("%s\n", n->term);
|
||||||
|
printf(" children: %d\n", n->childrenc);
|
||||||
|
printf(" parents: %d\n", n->parentc);
|
||||||
|
printf(" evidence: ");
|
||||||
|
for (i=0; i<12; i++)
|
||||||
|
printf("%d ", n->evidence[i]);
|
||||||
|
printf("\n");
|
||||||
|
printf(" accumulated evidence: ");
|
||||||
|
for (i=0; i<12; i++)
|
||||||
|
printf("%d ", n->acc_evidence[i]);
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,9 @@ struct node {
|
||||||
/* Child count and children */
|
/* Child count and children */
|
||||||
int childrenc;
|
int childrenc;
|
||||||
struct node *children[MAX_CHILDREN];
|
struct node *children[MAX_CHILDREN];
|
||||||
|
|
||||||
|
/* Flag to ensure that a node is only visited once in DAG operations */
|
||||||
|
char visited;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct node* term_array[MAX_NODES];
|
struct node* term_array[MAX_NODES];
|
||||||
|
|
Reference in New Issue