Skip to content

Commit 6620030

Browse files
authored
publish structure (#33)
* Don't query more than the limit articles * Let users know about the structure as a whole * Update version
1 parent 186f83a commit 6620030

File tree

23 files changed

+158
-129
lines changed

23 files changed

+158
-129
lines changed

src/bibx/__init__.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,21 @@
33
import logging
44
from typing import TextIO
55

6-
from bibx._entities.article import Article
7-
from bibx._entities.collection import Collection
8-
from bibx._entities.collection_builders.openalex import OpenAlexCollectionBuilder
9-
from bibx._entities.collection_builders.scopus_bib import ScopusBibCollectionBuilder
10-
from bibx._entities.collection_builders.scopus_ris import ScopusRisCollectionBuilder
11-
from bibx._entities.collection_builders.wos import WosCollectionBuilder
126
from bibx.algorithms.sap import Sap
7+
from bibx.article import Article
8+
from bibx.builders.openalex import HandleReferences, OpenAlexCollectionBuilder
9+
from bibx.builders.scopus_bib import ScopusBibCollectionBuilder
10+
from bibx.builders.scopus_ris import ScopusRisCollectionBuilder
11+
from bibx.builders.wos import WosCollectionBuilder
12+
from bibx.collection import Collection
1313
from bibx.exceptions import BibXError
1414

1515
logger = logging.getLogger(__name__)
1616

1717
__all__ = [
1818
"Article",
1919
"Collection",
20+
"HandleReferences",
2021
"Sap",
2122
"query_openalex",
2223
"read_any",
@@ -25,12 +26,16 @@
2526
"read_wos",
2627
]
2728

28-
__version__ = "0.3.1"
29+
__version__ = "0.4.0"
2930

3031

31-
def query_openalex(query: str, limit: int = 600) -> Collection:
32+
def query_openalex(
33+
query: str,
34+
limit: int = 600,
35+
references: HandleReferences = HandleReferences.BASIC,
36+
) -> Collection:
3237
"""Query OpenAlex and return a collection."""
33-
return OpenAlexCollectionBuilder(query, limit).build()
38+
return OpenAlexCollectionBuilder(query, limit, references=references).build()
3439

3540

3641
def read_scopus_bib(*files: TextIO) -> Collection:

src/bibx/_entities/__init__.py

Whitespace-only changes.

src/bibx/_entities/collection_builders/__init__.py

Whitespace-only changes.

src/bibx/_entities/collection_builders/base.py

Lines changed: 0 additions & 7 deletions
This file was deleted.

src/bibx/_entities/collection_builders/cross_ref.py

Lines changed: 0 additions & 15 deletions
This file was deleted.

src/bibx/_entities/collection_builders/generic.py

Lines changed: 0 additions & 10 deletions
This file was deleted.

src/bibx/algorithms/preprocess.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from xlsxwriter import Workbook
66
from xlsxwriter.worksheet import Worksheet
77

8-
from bibx import Collection
8+
from bibx.collection import Collection
99

1010
from .sap import BRANCH, LEAF, ROOT, TRUNK, Sap
1111

src/bibx/algorithms/sap.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
import networkx as nx
55
from networkx.algorithms.community.louvain import louvain_communities
66

7-
from bibx import Article, Collection
7+
from bibx.article import Article
8+
from bibx.collection import Collection
89

910
YEAR = "year"
1011
LEAF = "leaf"
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ def _keep_longest(a: str, b: str) -> str:
1515

1616
@dataclass
1717
class Article:
18+
"""A scientific article."""
19+
1820
label: str
1921
ids: set[str]
2022
authors: list[str] = field(default_factory=list)
@@ -55,10 +57,12 @@ def merge(self, other: "Article") -> "Article":
5557

5658
@property
5759
def key(self) -> str:
60+
"""Return the first ID of the article."""
5861
return next(iter(sorted(self.ids)))
5962

6063
@property
6164
def simple_label(self) -> Optional[str]:
65+
"""Return a simple label for the article."""
6266
pieces = {
6367
"AU": self.authors[0].replace(",", "") if self.authors else None,
6468
"PY": str(self.year) if self.year else None,
@@ -73,6 +77,7 @@ def simple_label(self) -> Optional[str]:
7377

7478
@property
7579
def permalink(self) -> Optional[str]:
80+
"""Return the permalink of the article."""
7681
if self._permalink is not None:
7782
return self._permalink
7883
if self.doi is not None:
@@ -81,21 +86,25 @@ def permalink(self) -> Optional[str]:
8186

8287
@property
8388
def simple_id(self) -> Optional[str]:
89+
"""Return a simple ID for the article."""
8490
if self.authors and self.year is not None:
8591
author = self.authors[0].split(" ")[0].replace(",", "")
8692
return f"{author}{self.year}".lower()
8793
return None
8894

8995
def __repr__(self) -> str:
96+
"""Return a string representation of the article."""
9097
return f"Article(ids={self.ids!r}, authors={self.authors!r})"
9198

9299
def add_simple_id(self) -> "Article":
100+
"""Add a simple ID to the article."""
93101
if self.simple_id is None:
94102
return self
95103
self.ids.add(f"simple:{self.simple_id}")
96104
return self
97105

98106
def set_simple_label(self) -> "Article":
107+
"""Set the simple label as the label of the article."""
99108
if self.simple_label is None:
100109
return self
101110
self.label = self.simple_label
@@ -104,6 +113,7 @@ def set_simple_label(self) -> "Article":
104113
def info(
105114
self,
106115
) -> dict[str, Union[str, int, list[str], None]]:
116+
"""Return a dictionary with the information of the article."""
107117
return {
108118
"permalink": self.permalink,
109119
"label": self.label,

src/bibx/builders/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Builders for diverse Collection types."""

0 commit comments

Comments
 (0)