예제 #1
0
def parse_references(model_node, model=None, progress=None):

    reference_list_node = model_node.find(ge_listOfReferences)

    if reference_list_node is None:
        return
    elif progress is None:
        pass
    elif not progress.wasCanceled():
        progress.setLabelText("Reading references...")
        progress.setRange(0, len(reference_list_node))
    elif progress.wasCanceled():
        return

    references = []
    for i, reference_node in enumerate(
            reference_list_node.iterfind(ge_reference)):

        if progress is None:
            pass
        elif not progress.wasCanceled():
            progress.setValue(i)
            QApplication.processEvents()
        else:
            return

        new_reference = Reference(id=reference_node.get("id"),
                                  year=reference_node.get("year"),
                                  title=reference_node.get("title"),
                                  journal=reference_node.get("journal"),
                                  url=reference_node.get("url"))

        author_list_node = reference_node.find(ge_listOfAuthors)
        if author_list_node is not None:
            authors = []
            for child in author_list_node.iterfind(ge_author):
                authors.append(
                    Author(firstname=child.get("firstname"),
                           lastname=child.get("lastname"),
                           initials=child.get("initials")))
            new_reference.authors = authors

        annotation = annotate_element_from_xml(reference_node)
        if annotation:
            for x in annotation:
                if x.collection == "pubmed":
                    new_reference.pmid = x.identifier
                elif x.collection == "pmc":
                    new_reference.pmc = x.identifier
                elif x.collection == "doi":
                    new_reference.doi = x.identifier

        if model is None:
            references.append(new_reference)
        else:
            model.add_reference(new_reference)

    return references
예제 #2
0
    def test_annotation_property(self):
        reference = Reference()
        reference.pmc = "1234"
        reference.pmid = "54321"
        reference.doi = "5555"

        assert Annotation("pubmed", reference.pmid) in reference.annotation
        assert Annotation("pmc", reference.pmc) in reference.annotation
        assert Annotation("doi", reference.doi) in reference.annotation