Skip to content

Commit

Permalink
Merge pull request #13 from clamsproject/10-clams-1.0.3
Browse files Browse the repository at this point in the history
10 clams 1.0.3
  • Loading branch information
marcverhagen committed Jul 7, 2023
2 parents e02c422 + 9558107 commit 855f49d
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 131 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ $ pip install clams-python==0.5.3

## Usage

Run the summarizer in stand-alone mode on one of the sample input documents and print an XML summary:
Run the summarizer in stand-alone mode on one of the sample input documents and print a JSON summary:

```bash
$ cd code
Expand Down Expand Up @@ -75,7 +75,7 @@ $ python summary.py examples/input-v7.mmif --barsandtone
}
```

> Not all options are fully implemented yet. In particular: (1) for slates the tool currently only prints the timeframe, not the information contained in it, (2) chyrons and credits are not implmented, and (3) entities are implmented, but need to be revamped. Also missing are some sanity checks that alert the user to overly complicated MMIF input, for example with many layers of the same kind.
> Not all options are fully implemented yet. In particular: (1) for slates the tool currently only prints the timeframe, not the information contained in it, (2) chyrons and credits are not implemented, and (3) entities are implemented, but need to be revamped. Also missing are some sanity checks that alert the user to overly complicated MMIF input, for example with many layers of the same kind.
If you want XML output (which tends to be a little bit more compact) you can run `json2xml.py` over the output.

Expand Down
53 changes: 25 additions & 28 deletions code/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,43 +13,40 @@
"""

from abc import abstractmethod
from clams.app import ClamsApp
from clams.appmetadata import AppMetadata
from clams.restify import Restifier
from mmif.serialize import Mmif
from mmif.vocabulary import DocumentTypes, AnnotationTypes
from lapps.discriminators import Uri

import metadata
import summary
from server import ClamsConsumer, Restifier


VERSION = '0.2.0'
LICENSE = 'Apache 2.0'
MMIF_VERSION = '0.4.2'
MMIF_PYTHON_VERSION = '0.4.8'
CLAMS_PYTHON_VERSION = '0.5.3'
class ClamsConsumer(ClamsApp):

"""For the summarizer, partially because like a ClamsProducer it also generates
JSON, all the ClamsConsumer does is add consume and _consume methods. The annotate
and _annotate methods are inherited, but tweaked to trivially return the input Mmif."""

# TODO: we still may want to add this to clams-python

def _annotate(self, mmif: Mmif, **runtime_params) -> Mmif:
"""Since this is a consumer it just bounces the input back."""
return mmif

def consume(self, mmif, **kwargs) -> str:
return self._consume(mmif, **kwargs)

@abstractmethod
def _consume(self, mmif, **kwargs) -> str:
raise NotImplementedError()


class MmifSummarizer(ClamsConsumer):

def _consumermetadata(self):
self.metadata = \
AppMetadata(
identifier="https://apps.clams.ai/mmif-summarizer",
url='https://github.com/clamsproject/mmif-summarizer',
name="MMIF Summarizer",
description="Summarize a MMIF file.",
mmif_version=MMIF_VERSION,
app_version=VERSION,
app_license=LICENSE,
analyzer_version=VERSION,
analyzer_license=LICENSE)
self.metadata.add_input(DocumentTypes.TextDocument, required=False)
self.metadata.add_input(AnnotationTypes.TimeFrame, required=False)
self.metadata.add_input(AnnotationTypes.BoundingBox, required=False)
self.metadata.add_input(AnnotationTypes.Alignment, required=False)
self.metadata.add_input(Uri.TOKEN, required=False)
self.metadata.add_input(Uri.NE, required=False)
return self.metadata
def _appmetadata(self) -> AppMetadata:
return metadata.appmetadata()

def _consume(self, mmif, **kwargs):
self.mmif = mmif if type(mmif) is Mmif else Mmif(mmif)
Expand All @@ -59,7 +56,7 @@ def _consume(self, mmif, **kwargs):

def start_service():
summarizer = MmifSummarizer()
service = Restifier(summarizer, mimetype='application/xml')
service = Restifier(summarizer)
service.run()


Expand Down
42 changes: 42 additions & 0 deletions code/metadata.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
from mmif import DocumentTypes, AnnotationTypes

from clams.appmetadata import AppMetadata
from lapps.discriminators import Uri


APP_VERSION = '0.2.0'
APP_LICENSE = 'Apache 2.0'
ANALYZER_VERSION = '0.1.0'
ANALYZER_LICENSE = 'Apache 2.0'
MMIF_VERSION = '0.4.2'
MMIF_PYTHON_VERSION = '0.4.8'
CLAMS_PYTHON_VERSION = '0.5.3'


# DO NOT CHANGE the function name
def appmetadata() -> AppMetadata:
metadata = AppMetadata(
name="MMIF Summarizer",
description="Summarize a MMIF file.",
identifier="https://apps.clams.ai/mmif-summarizer",
url='https://github.com/clamsproject/mmif-summarizer',
app_version=APP_VERSION,
app_license=APP_LICENSE,
analyzer_version=ANALYZER_VERSION,
analyzer_license=ANALYZER_LICENSE,
)

metadata.add_input(DocumentTypes.TextDocument, required=False)
metadata.add_input(AnnotationTypes.TimeFrame, required=False)
metadata.add_input(AnnotationTypes.BoundingBox, required=False)
metadata.add_input(AnnotationTypes.Alignment, required=False)
metadata.add_input(Uri.TOKEN, required=False)
metadata.add_input(Uri.NE, required=False)

return metadata


# DO NOT CHANGE the main block
if __name__ == '__main__':
import sys
sys.stdout.write(appmetadata().json(indent=2))
2 changes: 1 addition & 1 deletion code/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
clams-python==0.5.3
clams-python==1.0.3
100 changes: 0 additions & 100 deletions code/server.py

This file was deleted.

1 change: 1 addition & 0 deletions code/summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import names
from config import GRANULARITY

VERSION = '0.1.0'

class SummaryException(Exception):
pass
Expand Down

0 comments on commit 855f49d

Please sign in to comment.