LocationBasedServices/smartguide/pipeline/pr-dev This commit looks good
Introduce a batch script and Elasticsearch index to pre-aggregate institution patents via assignee and inventor name matching, expose them through a new API endpoint, and update the institution patents page with match-type filtering.
39 lines
1.1 KiB
Python
39 lines
1.1 KiB
Python
#!/usr/bin/env python3
|
|
"""Index org_patents for an institution."""
|
|
from __future__ import annotations
|
|
|
|
import argparse
|
|
import asyncio
|
|
import logging
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
current_dir = Path(__file__).resolve().parent
|
|
sys.path.insert(0, str(current_dir.parent / "src" / "main"))
|
|
|
|
from dotenv import load_dotenv
|
|
|
|
load_dotenv(dotenv_path=current_dir.parent / "src" / "main" / "inse" / ".env")
|
|
|
|
from inse.patents.org.logic import index_org_patents_for_institution
|
|
|
|
logging.basicConfig(level=logging.INFO, format="%(levelname)s %(message)s")
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
async def main() -> None:
|
|
parser = argparse.ArgumentParser(description="Index org_patents for an institution.")
|
|
parser.add_argument(
|
|
"--institution-id",
|
|
required=True,
|
|
help="OpenAlex institution ID, e.g. I62318514",
|
|
)
|
|
args = parser.parse_args()
|
|
|
|
count = await index_org_patents_for_institution(args.institution_id)
|
|
logger.info("Finished indexing %d patents for institution %s", count, args.institution_id)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(main())
|