aboutsummaryrefslogtreecommitdiffstats
path: root/test/extractor/text/test_summary.py
diff options
context:
space:
mode:
Diffstat (limited to 'test/extractor/text/test_summary.py')
-rw-r--r--test/extractor/text/test_summary.py53
1 files changed, 53 insertions, 0 deletions
diff --git a/test/extractor/text/test_summary.py b/test/extractor/text/test_summary.py
new file mode 100644
index 0000000..78d3002
--- /dev/null
+++ b/test/extractor/text/test_summary.py
@@ -0,0 +1,53 @@
+
+# standard imports
+import os
+import unittest
+import warnings
+
+# bsie imports
+from bsie.extractor import base
+from bsie.matcher import nodes
+from bsie.reader.document import Document
+from bsie.utils import bsfs, ns
+
+# objects to test
+from bsie.extractor.text.summary import Summary
+
+
+## code ##
+
+class TestTextMetrics(unittest.TestCase):
+
+ def test_schema(self):
+ self.assertEqual(Summary().schema,
+ bsfs.schema.from_string(base.SCHEMA_PREAMBLE + '''
+ bse:summary rdfs:subClassOf bsfs:Predicate ;
+ rdfs:domain bsn:Entity ;
+ rdfs:range xsd:string ;
+ bsfs:unique "true"^^xsd:boolean .
+ '''))
+
+ def test_extract(self):
+ # setup
+ rdr = Document()
+ ext = Summary(max_length=20, num_beams=1)
+ subject = nodes.Entity(ucid='abc123')
+ principals = set(ext.principals)
+ path = os.path.join(os.path.dirname(__file__), 'example-en.txt')
+ # fetch document
+ text = rdr(path)
+
+ with warnings.catch_warnings():
+ warnings.simplefilter('ignore', category=FutureWarning)
+ triples = list(ext.extract(subject, text, principals))
+
+ self.assertEqual(triples, [
+ (subject, ext.schema.predicate(ns.bse.summary),
+ 'Alice is tired of sitting by her sister on the bank')])
+
+## main ##
+
+if __name__ == '__main__':
+ unittest.main()
+
+## EOF ##