Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion link-grammar/dict-common/dict-structures.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ typedef enum
} Exp_type;

#ifndef SWIG
#define COST_MAX_DEC_PLACES 3 /* Max. decimal places when printing. */
#define COST_MAX_DEC_PLACES 5 /* Max. decimal places when printing. */
static const float cost_epsilon = 1E-5f;

#define EXPTAG_SZ 100 /* Initial size for the Exptag array. */
Expand Down
45 changes: 45 additions & 0 deletions link-grammar/linkage/score.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

#include <stdarg.h>
#include "api-structures.h" // Needed for Parse_Options
#include "connectors.h"
#include "disjunct-utils.h" // Needed for Disjunct
#include "linkage.h"
#include "score.h"
Expand Down Expand Up @@ -68,10 +69,54 @@ static float compute_disjunct_cost(Linkage lkg)
return lcost;
}

/// Compute the extra cost of a multi-connector being used multiple
/// times. Any cost on that multi-connector needs to be added for each
/// usage of it.
static float compute_multi_cost(Linkage lkg)
{
size_t lword = 0;
float mcost = 0.0;
for (size_t i = 0; i < lkg->num_words; i++)
{
Disjunct * dj = lkg->chosen_disjuncts[i];
if (NULL == dj) continue;

// Look at the right-going connectors.
for (Connector* rcon = dj->right; rcon; rcon=rcon->next)
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the left connectors are ignored?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because this was a prototype and I did not do those.

{
// No-op if not a multi-connector.
if (false == rcon->multi) continue;

// Find the links using this connector.
for (size_t l = 0; l < lkg->num_links; l++)
{
// The link is not even for this word. Ignore it.
if (lword != lkg->link_array[l].lw) continue;

// Find the links that are using our multi-connector.
for (Connector* wrc = lkg->link_array[l].rc; wrc; wrc=wrc->next)
{
// Skip if no match.
if (strcmp(rcon->desc->string, wrc->desc->string)) continue;
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I wrote in the general response (in the wrong box...), there is 1-1 match between condesct_t elements and connector strings, disregarding if the connectors are multi or not. Thus the condesc_t strings don't include@.
So there is a need for a different comparison.

dj->cost += 0.0001;
mcost += 1.0;
}
}
}
lword++; // increment only if disjunct is non-null.
Comment thread
ampli marked this conversation as resolved.
}
return mcost;
}

/** Assign parse score (cost) to linkage, used for parse ranking. */
void linkage_score(Linkage lkg, Parse_Options opts)
{
float mcost = compute_multi_cost(lkg);

lkg->lifo.unused_word_cost = unused_word_cost(lkg);
lkg->lifo.disjunct_cost = compute_disjunct_cost(lkg);
lkg->lifo.link_cost = compute_link_cost(lkg);

// printf("duuude mcost=%f\n", mcost);
// lkg->lifo.disjunct_cost += 0.0001 * mcost;
}