-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?

5
  • 1
    So what is the issue? Commented Jul 14, 2016 at 21:41
  • Are you sure you want to map from (Gender, Case) to Something, rather than associate each Something with (Gender, Case)? Commented Jul 14, 2016 at 21:41
  • arrays already have any number of dimensions with any scalar value as keys up to whatever the memory limit of php is. Commented Jul 14, 2016 at 21:52
  • 1
    Probably the easiest way is just this: std::map<std::vector<std::string>, std::string>, albeit the syntax will be different, sg like: v[{"a", "b", "c"}] = "d";. Commented Jul 14, 2016 at 21:58
  • Could write with pseudocode what do you want to achieve? Commented Jul 15, 2016 at 1:30

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.