Tensors over Semirings for Latent-Variable Weighted Logic Programs