-2

I'm trying to think about the appropriate data structure for storing grammatical paradigms. I want something like an associative array, but with an arbitrary number of dimensions. In a simple case, it's easy to think of the data structure. If the two dimensions of the paradigm are as follows...

Gender (Masculine, Feminine, Neuter)

Case (Nominative, Accusative, Dative, Genitive)

... then it makes sense to use a hash map in C++, or an associative array in PHP:

$value['Masculine']['Accusative'] = 'foo';
$value['Neuter']['Dative'] = 'foo';

The problem is that, for a given language, any number of ‘dimensions’ might be important. (There is surely an upper bound, but I don't know what that is in advance.) I want the user to specify what the important values are, and to be able to change them dynamically as well.

Is there any sort of data structure that has that flexibility, or would I need to create my own with a special class, or something like that?

adam.baker
  • 1,447
  • 1
  • 14
  • 30

1 Answers1

0

Following lorro's answer and building on this question, it could be done by creating a has data structure with a vector or set as the key.

Here is a Qt approach; presumably it works similarly with the std tools.

QHash< QSet<QString> , QString > paradigm;

QSet<QString> descriptor1;
descriptor1 << "Nominative" << "Masculine";
paradigm[descriptor1] = "foo";

QSet<QString> descriptor2;
descriptor2 << "Neuter" << "Dative";
paradigm[descriptor2] = "bar";

QSet<QString> descriptor3;
descriptor3 << "Feminine" << "Genitive";

qDebug() << paradigm.value(descriptor1, "No value")
         << paradigm.value(descriptor2, "No value")
         << paradigm.value(descriptor3, "No value");

Output:

"foo" "bar" "No value"

PHP arrays can only be keyed by strings and integers, however, so PHP would require a different approach.

Community
  • 1
  • 1
adam.baker
  • 1,447
  • 1
  • 14
  • 30