Extract features from a survey I need to use the answers from a questionnaire for training a classifier.
I discovered that some questions can have nested sub-questions..
Let's say (just an example) that I want to predict whether a person is going to buy a house based on the following questions:

1) What is your gender?
[] male
[x] female
[] I prefer not to answer


in the case the answer is female (as in the example above) a sub-question is ansked

1_female) are you pregnant?
[x] yes
[] no


Then the questionnaire continues..

How should I use these features to train my model?

Option 1)
Treat them separately and transform them with one-hot-encoding
I will have then the feature vector

gender_male - gender_female - gender_not_answered - pregnant_empty - pregnant_yes - pregnant_no
     0      -        1      -         0           -        0       -       1      -        0


Obviously the feature pregnant_empty will be coded with 1 for all the males

Option 2)
Merge the 2 answers and encoding the concatenation

gender_female_pregnant_yes - gender_female_pregnant_not - gender_male - gender_not_answered
     1                     -                 0          -      0      -     0


Other options?

Please treat this just as an example... the problem is that in a real scenario


the nested question could appear with 2 or more answers
expanding the features as in option 2 will make my feature vector explode..


I hope my question was clear enough
The simplest is to keep your features separate and add a synthetic feature, feature cross, that captures the relationship between those features you mention that can possibly be nested.

For example, in a neuronal network based classifier (e.g., TensorFlow), the model will learn the 'correct' weight for those combinations of features' values that are impossible to happen (e.g., male and pregnant), excluding wrong data cases obviously. 

In the end... you just want the cartesian product among the features that you need to 'cross'. And yes, your vector will grow.