<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def query_nodes(self, bel: Optional[str] = None, type: Optional[str] = None, namespace: Optional[str] = None, name: Optional[str] = None, ) -> List[Node]: """Query nodes in the database. :param bel: BEL term that describes the biological entity. e.g. ``p(HGNC:APP)`` :param type: Type of the biological entity. e.g. Protein :param namespace: Namespace keyword that is used in BEL. e.g. HGNC :param name: Name of the biological entity. e.g. APP """

        q = self.session.query(Node)

        if bel:
            q = q.filter(Node.bel.contains(bel))

        if type:
            q = q.filter(Node.type == type)

        if namespace or name:
            q = q.join(NamespaceEntry)

            if namespace:
                q = q.join(Namespace).filter(Namespace.keyword.contains(namespace))

            if name:
                q = q.filter(NamespaceEntry.name.contains(name))

        return q