<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(self, terms=None, negated_terms=None):
 """ Basic boolean query, using inference. Arguments: - terms: list list of class ids. Returns the set of subjects that have at least one inferred annotation to each of the specified classes. - negated_terms: list list of class ids. Filters the set of subjects so that there are no inferred annotations to any of the specified classes """


        if terms is None:
            terms = []
        matches_all = 'owl:Thing' in terms
        if negated_terms is None:
            negated_terms = []
        termset = set(terms)
        negated_termset = set(negated_terms)
        matches = []
        n_terms = len(termset)
        for subj in self.subjects:
            if matches_all or len(termset.intersection(self.inferred_types(subj))) == n_terms:
                if len(negated_termset.intersection(self.inferred_types(subj))) == 0:
                    matches.append(subj)
        return matches