Similar Items: Weighted Logics for Nested Words and Algebraic Formal Power Series