예제 #1
0
    def ingest(cls, package="osp.fields", path="data/fields.csv"):

        """
        Ingest fields.

        Args:
            package (str)
            path (str)
        """

        reader = read_csv(package, path)

        for row in reader:

            # Sanifize field names.
            pf = clean_field_name(row["Primary Field"])
            sf = clean_field_name(row["Secondary Field"])

            # Parse abbreviations.
            abbrs = parse_abbrs(row["ABBRV"])
            if abbrs:
                abbrs = filter_abbrs(abbrs)

            # If parent field, write row.
            if bool(row["Alpha Category"]):
                Field.create(name=pf)

            # Query for a parent field.
            field = Field.select().where(Field.name == pf).first()

            if field:

                Subfield.create(name=sf, abbreviations=abbrs, field=field)
예제 #2
0
    def ingest(cls, package='osp.fields', path='data/fields.csv'):
        """
        Ingest fields.

        Args:
            package (str)
            path (str)
        """

        reader = read_csv(package, path)

        for row in reader:

            # Sanifize field names.
            pf = clean_field_name(row['Primary Field'])
            sf = clean_field_name(row['Secondary Field'])

            # Parse abbreviations.
            abbrs = parse_abbrs(row['ABBRV'])
            if abbrs: abbrs = filter_abbrs(abbrs)

            # If parent field, write row.
            if bool(row['Alpha Category']):
                Field.create(name=pf)

            # Query for a parent field.
            field = Field.select().where(Field.name == pf).first()

            if field:

                Subfield.create(
                    name=sf,
                    abbreviations=abbrs,
                    field=field,
                )
예제 #3
0
def test_field_facets(add_citation, add_subfield, add_subfield_document):
    """
    field_facets() should provide a list of label/value/count dicts.
    """

    f1 = Field.create(name='Field 1')
    f2 = Field.create(name='Field 2')
    f3 = Field.create(name='Field 3')

    sf1 = add_subfield(field=f1)
    sf2 = add_subfield(field=f2)
    sf3 = add_subfield(field=f3)

    for i in range(3):
        c = add_citation()
        add_subfield_document(subfield=sf1, document=c.document)

    for i in range(2):
        c = add_citation()
        add_subfield_document(subfield=sf2, document=c.document)

    for i in range(1):
        c = add_citation()
        add_subfield_document(subfield=sf3, document=c.document)

    Citation_Index.es_insert()
    Field_Index.es_insert()

    facets = field_facets()

    assert facets == [
        dict(label='Field 1', value=f1.id, count=3),
        dict(label='Field 2', value=f2.id, count=2),
        dict(label='Field 3', value=f3.id, count=1),
    ]
    def _subfield(
        name='Field',
        abbreviations=None,
        field=None,
    ):

        if not field:
            field = Field.create(name='Parent')

        return Subfield.create(
            name=name,
            abbreviations=abbreviations,
            field=field,
        )
예제 #5
0
    def _subfield(
        name='Field',
        abbreviations=None,
        field=None,
    ):

        if not field:
            field = Field.create(name='Parent')

        return Subfield.create(
            name=name,
            abbreviations=abbreviations,
            field=field,
        )
def test_field_facets(add_citation, add_subfield, add_subfield_document):

    """
    field_facets() should provide a list of label/value/count dicts.
    """

    f1 = Field.create(name="Field 1")
    f2 = Field.create(name="Field 2")
    f3 = Field.create(name="Field 3")

    sf1 = add_subfield(field=f1)
    sf2 = add_subfield(field=f2)
    sf3 = add_subfield(field=f3)

    for i in range(3):
        c = add_citation()
        add_subfield_document(subfield=sf1, document=c.document)

    for i in range(2):
        c = add_citation()
        add_subfield_document(subfield=sf2, document=c.document)

    for i in range(1):
        c = add_citation()
        add_subfield_document(subfield=sf3, document=c.document)

    Citation_Index.es_insert()
    Field_Index.es_insert()

    facets = field_facets()

    assert facets == [
        dict(label="Field 1", value=f1.id, count=3),
        dict(label="Field 2", value=f2.id, count=2),
        dict(label="Field 3", value=f3.id, count=1),
    ]