Syntactic Matching of Trajectories for Ambient Intelligence Applications