Infer word id from source id

Fixes sorting issues in the text - the xml nodes are not in the
correct order due to grammatical reasons.