├── .DS_Store ├── .gitignore ├── .vscode └── settings.json ├── LICENSE ├── README.md ├── doc ├── Makefile ├── make.bat ├── python │ ├── .DS_Store │ └── kopl │ │ ├── __init__.py │ │ ├── data.py │ │ ├── kopl.py │ │ ├── test │ │ ├── __init__.py │ │ └── test_example.py │ │ └── util.py └── source │ ├── .DS_Store │ ├── 0_intro.rst │ ├── 1_knowledge.rst │ ├── 2_function.rst │ ├── 3_install.rst │ ├── 4_helloworld.rst │ ├── 5_example.rst │ ├── 6_service.rst │ ├── 7_kopl.rst │ ├── _build │ ├── doctrees │ │ ├── 0_intro.doctree │ │ ├── 1_knowledge.doctree │ │ ├── 2_function.doctree │ │ ├── 3_install.doctree │ │ ├── 4_helloworld.doctree │ │ ├── 5_example.doctree │ │ ├── 6_service.doctree │ │ ├── 7_kopl.doctree │ │ ├── environment.pickle │ │ └── index.doctree │ └── html │ │ ├── .buildinfo │ │ ├── .doctrees │ │ ├── 0_intro.doctree │ │ ├── 1_knowledge.doctree │ │ ├── 2_function.doctree │ │ ├── 3_install.doctree │ │ ├── 4_helloworld.doctree │ │ ├── 5_example.doctree │ │ ├── 6_service.doctree │ │ ├── 7_kopl.doctree │ │ ├── doc_1_knowledge.doctree │ │ ├── doc_2_function.doctree │ │ ├── doc_3_engine.doctree │ │ ├── doc_4_example.doctree │ │ ├── environment.pickle │ │ ├── exam_1_input.doctree │ │ ├── exam_2_schema.doctree │ │ ├── example.doctree │ │ ├── function.doctree │ │ ├── glossary.doctree │ │ ├── helloworld.doctree │ │ ├── index.doctree │ │ ├── install.doctree │ │ ├── intro.doctree │ │ ├── knowledge.doctree │ │ ├── kopl.doctree │ │ ├── quick_start.doctree │ │ ├── schema.doctree │ │ └── service.doctree │ │ ├── 0_intro.html │ │ ├── 1_knowledge.html │ │ ├── 2_function.html │ │ ├── 3_install.html │ │ ├── 4_helloworld.html │ │ ├── 5_example.html │ │ ├── 6_service.html │ │ ├── 7_kopl.html │ │ ├── _images │ │ ├── demo1.png │ │ ├── demo10.png │ │ ├── demo11.png │ │ ├── demo12.png │ │ ├── demo13.png │ │ ├── demo2.png │ │ ├── demo3.png │ │ ├── demo4.png │ │ ├── demo5.png │ │ ├── demo6.png │ │ ├── demo7.png │ │ ├── demo8.png │ │ ├── demo9.png │ │ └── knowledge_element.jpg │ │ ├── _modules │ │ ├── index.html │ │ ├── kopl.html │ │ └── kopl │ │ │ └── kopl.html │ │ ├── _sources │ │ ├── 0_intro.rst.txt │ │ ├── 1_knowledge.rst.txt │ │ ├── 2_function.rst.txt │ │ ├── 3_install.rst.txt │ │ ├── 4_helloworld.rst.txt │ │ ├── 5_example.rst.txt │ │ ├── 6_service.rst.txt │ │ ├── 7_kopl.rst.txt │ │ ├── doc_1_knowledge.rst.txt │ │ ├── doc_2_function.rst.txt │ │ ├── doc_3_engine.rst.txt │ │ ├── doc_4_example.rst.txt │ │ ├── exam_1_input.rst.txt │ │ ├── exam_2_schema.rst.txt │ │ ├── example.rst.txt │ │ ├── function.rst.txt │ │ ├── glossary.rst.txt │ │ ├── helloworld.rst.txt │ │ ├── index.rst.txt │ │ ├── install.rst.txt │ │ ├── intro.rst.txt │ │ ├── knowledge.rst.txt │ │ ├── kopl.rst.txt │ │ ├── quick_start.rst.txt │ │ ├── schema.rst.txt │ │ └── service.rst.txt │ │ ├── _static │ │ ├── basic.css │ │ ├── css │ │ │ ├── badge_only.css │ │ │ ├── fonts │ │ │ │ ├── Roboto-Slab-Bold.woff │ │ │ │ ├── Roboto-Slab-Bold.woff2 │ │ │ │ ├── Roboto-Slab-Regular.woff │ │ │ │ ├── Roboto-Slab-Regular.woff2 │ │ │ │ ├── fontawesome-webfont.eot │ │ │ │ ├── fontawesome-webfont.svg │ │ │ │ ├── fontawesome-webfont.ttf │ │ │ │ ├── fontawesome-webfont.woff │ │ │ │ ├── fontawesome-webfont.woff2 │ │ │ │ ├── lato-bold-italic.woff │ │ │ │ ├── lato-bold-italic.woff2 │ │ │ │ ├── lato-bold.woff │ │ │ │ ├── lato-bold.woff2 │ │ │ │ ├── lato-normal-italic.woff │ │ │ │ ├── lato-normal-italic.woff2 │ │ │ │ ├── lato-normal.woff │ │ │ │ └── lato-normal.woff2 │ │ │ └── theme.css │ │ ├── doctools.js │ │ ├── documentation_options.js │ │ ├── file.png │ │ ├── jquery-3.5.1.js │ │ ├── jquery.js │ │ ├── js │ │ │ ├── badge_only.js │ │ │ ├── html5shiv-printshiv.min.js │ │ │ ├── html5shiv.min.js │ │ │ └── theme.js │ │ ├── language_data.js │ │ ├── logo.png │ │ ├── minus.png │ │ ├── plus.png │ │ ├── pygments.css │ │ ├── searchtools.js │ │ ├── underscore-1.13.1.js │ │ └── underscore.js │ │ ├── doc_1_knowledge.html │ │ ├── doc_2_function.html │ │ ├── doc_3_engine.html │ │ ├── doc_4_example.html │ │ ├── exam_1_input.html │ │ ├── exam_2_schema.html │ │ ├── example.html │ │ ├── function.html │ │ ├── genindex.html │ │ ├── glossary.html │ │ ├── helloworld.html │ │ ├── index.html │ │ ├── install.html │ │ ├── intro.html │ │ ├── knowledge.html │ │ ├── kopl.html │ │ ├── objects.inv │ │ ├── py-modindex.html │ │ ├── quick_start.html │ │ ├── schema.html │ │ ├── search.html │ │ ├── searchindex.js │ │ └── service.html │ ├── _static │ └── .DS_Store │ ├── conf.py │ ├── demo1.png │ ├── demo10.png │ ├── demo11.png │ ├── demo12.png │ ├── demo13.png │ ├── demo2.png │ ├── demo3.png │ ├── demo4.png │ ├── demo5.png │ ├── demo6.png │ ├── demo7.png │ ├── demo8.png │ ├── demo9.png │ ├── index.rst │ ├── knowledge_element.jpg │ └── logo.png └── src └── kopl ├── __init__.py ├── data.py ├── kopl.py ├── test ├── __init__.py └── test_example.py └── util.py /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THU-KEG/KoPL/486c07bd83ea32268ff90fa6942cc9f7e1574ae5/.DS_Store -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | pip-wheel-metadata/ 24 | share/python-wheels/ 25 | *.egg-info/ 26 | .installed.cfg 27 | *.egg 28 | MANIFEST 29 | 30 | # PyInstaller 31 | # Usually these files are written by a python script from a template 32 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 33 | *.manifest 34 | *.spec 35 | 36 | # Installer logs 37 | pip-log.txt 38 | pip-delete-this-directory.txt 39 | 40 | # Unit test / coverage reports 41 | htmlcov/ 42 | .tox/ 43 | .nox/ 44 | .coverage 45 | .coverage.* 46 | .cache 47 | nosetests.xml 48 | coverage.xml 49 | *.cover 50 | *.py,cover 51 | .hypothesis/ 52 | .pytest_cache/ 53 | 54 | # Translations 55 | *.mo 56 | *.pot 57 | 58 | # Django stuff: 59 | *.log 60 | local_settings.py 61 | db.sqlite3 62 | db.sqlite3-journal 63 | 64 | # Flask stuff: 65 | instance/ 66 | .webassets-cache 67 | 68 | # Scrapy stuff: 69 | .scrapy 70 | 71 | # Sphinx documentation 72 | docs/_build/ 73 | 74 | # PyBuilder 75 | target/ 76 | 77 | # Jupyter Notebook 78 | .ipynb_checkpoints 79 | 80 | # IPython 81 | profile_default/ 82 | ipython_config.py 83 | 84 | # pyenv 85 | .python-version 86 | 87 | # pipenv 88 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 89 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 90 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 91 | # install all needed dependencies. 92 | #Pipfile.lock 93 | 94 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow 95 | __pypackages__/ 96 | 97 | # Celery stuff 98 | celerybeat-schedule 99 | celerybeat.pid 100 | 101 | # SageMath parsed files 102 | *.sage.py 103 | 104 | # Environments 105 | .env 106 | .venv 107 | env/ 108 | venv/ 109 | ENV/ 110 | env.bak/ 111 | venv.bak/ 112 | 113 | # Spyder project settings 114 | .spyderproject 115 | .spyproject 116 | 117 | # Rope project settings 118 | .ropeproject 119 | 120 | # mkdocs documentation 121 | /site 122 | 123 | # mypy 124 | .mypy_cache/ 125 | .dmypy.json 126 | dmypy.json 127 | 128 | # Pyre type checker 129 | .pyre/ 130 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | <<<<<<< HEAD 3 | "restructuredtext.confPath": "${workspaceFolder}\\doc\\source", 4 | "esbonio.sphinx.confDir": "${workspaceFolder}\\doc\\source" 5 | ======= 6 | "restructuredtext.confPath": "${workspaceFolder}/doc/source" 7 | >>>>>>> 5688cef5c141387c80afe169d29346d3ac7f3963 8 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 THU-KEG 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # KoPL: 面向知识的推理问答编程语言 2 | 3 | [安装](#安装) | [快速开始](#快速开始) | [文档](#文档) | [网站](#网站) 4 | 5 | KoPL全称 Knowledge oriented Programing Language, 是一个为复杂推理问答而设计的编程语言。我们可以将自然语言问题表示为由基本函数组合而成的KoPL程序,程序运行的结果就是问题的答案。目前,KoPL的27个基本函数覆盖对多种知识元素(如概念、实体、关系、属性、修饰符等)的操作,并支持多种问题类型(如计数、事实验证、比较等)的查询。KoPL提供透明的复杂问题推理过程,易于理解和使用。KoPL面向知识库、文本等不同形式的知识资源,可扩展性强。 6 | 7 | 下面的代码演示了如何使用Python代码,实现对一个自然语言问题的推理问答。 8 | 9 | ```python 10 | from kopl.kopl import KoPLEngine 11 | from kopl.test.test_example import example_kb 12 | 13 | engine = KoPLEngine(example_kb) # 创建可以在example_kb这个知识库上进行操作的engine示例 14 | 15 | # 查询问题:Who is taller, LeBron James Jr. or his father? 16 | ans = engine.SelectBetween( # 在两个实体中,查询'height'更大的实体 17 | engine.Find('LeBron James Jr.'), # 找到实体'LeBron James Jr' 18 | engine.Relate( # 找到与'LeBron James Jr'的'father 19 | engine.Find('LeBron James Jr.'), # 找到实体'LeBron James Jr' 20 | 'father', # 关系标签 21 | 'forward' # ’forward‘代表'LeBron James Jr'为头实体 22 | ), 23 | 'height', # 属性标签 24 | 'greater' # 查询属性值更大的实体 25 | ) 26 | 27 | print(ans) # ans是实体名字列表 28 | 29 | ``` 30 | 31 | 在这个示例里,我们查询LeBron James Jr.和他的父亲谁更高,KoPL程序给出了正确的答案: LeBron James! 32 | 33 | # 安装 34 | 35 | KoPL支持Linux (e.g., Ubuntu/CentOS),macOS,Windows。 36 | 37 | 其依赖为: 38 | 39 | * python >= 3.6 40 | 41 | * tqdm >= 4.62 42 | 43 | 44 | KoPL提供pip安装, 下面将展示Ubuntu的安装命令: 45 | 46 | ```bash 47 | $ pip install KoPL tqdm 48 | ``` 49 | 50 | 运行下面的代码 51 | 52 | ```python 53 | import kopl 54 | 55 | from kopl.test.test_example import * 56 | 57 | run_test() 58 | ``` 59 | 如果测试运行成功,恭喜您已经安装成功。 60 | 61 | # 快速开始 62 | 您可以准备自己的知识库,使用KoPL实现推理问答。知识库的格式请参考 [知识库](https://kopl.xlore.cn/doc/4_helloworld.html#id1)。 63 | 更多使用KoPL程序进行的简单问答请参考 [简单问答](https://kopl.xlore.cn/doc/5_example.html#id2),复杂问答请参考 [复杂问答](https://kopl.xlore.cn/doc/5_example.html#id8)。 64 | 65 | 您也可以使用我们为您提供的[查询服务](https://kopl.xlore.cn/queryService),快速开启KoPL之旅。 66 | 67 | # 文档 68 | 我们为您提供了KoPL[文档](https://kopl.xlore.cn/doc/index.html),详细介绍了KoPL面向的知识元素,KoPL的基本函数,KoPL引擎的API。 69 | 70 | # 网站 71 | https://kopl.xlore.cn 72 | -------------------------------------------------------------------------------- /doc/Makefile: -------------------------------------------------------------------------------- 1 | # Minimal makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line, and also 5 | # from the environment for the first two. 6 | SPHINXOPTS ?= 7 | SPHINXBUILD ?= sphinx-build 8 | SOURCEDIR = source 9 | BUILDDIR = build 10 | 11 | # Put it first so that "make" without argument is like "make help". 12 | help: 13 | @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 14 | 15 | .PHONY: help Makefile 16 | 17 | # Catch-all target: route all unknown targets to Sphinx using the new 18 | # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). 19 | %: Makefile 20 | @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 21 | -------------------------------------------------------------------------------- /doc/make.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | pushd %~dp0 4 | 5 | REM Command file for Sphinx documentation 6 | 7 | if "%SPHINXBUILD%" == "" ( 8 | set SPHINXBUILD=sphinx-build 9 | ) 10 | set SOURCEDIR=source 11 | set BUILDDIR=build 12 | 13 | if "%1" == "" goto help 14 | 15 | %SPHINXBUILD% >NUL 2>NUL 16 | if errorlevel 9009 ( 17 | echo. 18 | echo.The 'sphinx-build' command was not found. Make sure you have Sphinx 19 | echo.installed, then set the SPHINXBUILD environment variable to point 20 | echo.to the full path of the 'sphinx-build' executable. Alternatively you 21 | echo.may add the Sphinx directory to PATH. 22 | echo. 23 | echo.If you don't have Sphinx installed, grab it from 24 | echo.https://www.sphinx-doc.org/ 25 | exit /b 1 26 | ) 27 | 28 | %SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% 29 | goto end 30 | 31 | :help 32 | %SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% 33 | 34 | :end 35 | popd 36 | -------------------------------------------------------------------------------- /doc/python/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THU-KEG/KoPL/486c07bd83ea32268ff90fa6942cc9f7e1574ae5/doc/python/.DS_Store -------------------------------------------------------------------------------- /doc/python/kopl/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THU-KEG/KoPL/486c07bd83ea32268ff90fa6942cc9f7e1574ae5/doc/python/kopl/__init__.py -------------------------------------------------------------------------------- /doc/python/kopl/data.py: -------------------------------------------------------------------------------- 1 | import json 2 | import os 3 | from collections import defaultdict 4 | from queue import Queue 5 | from datetime import date 6 | from tqdm import tqdm 7 | from kopl.util import ValueClass, comp 8 | 9 | 10 | 11 | class KB(object): 12 | def __init__(self, kb): 13 | self.entities = {} 14 | for cid in kb['concepts']: 15 | self.entities[cid] = kb['concepts'][cid] 16 | self.entities[cid]['relations'] = [] 17 | self.entities[cid]['attributes'] = [] 18 | self.entities[cid]['isA'] = self.entities[cid].pop('subclassOf') 19 | for eid in kb['entities']: 20 | self.entities[eid] = kb['entities'][eid] 21 | self.entities[eid]['isA'] = self.entities[eid].pop('instanceOf') 22 | print('process concept') 23 | self.name_to_id = defaultdict(list) # id 包含 concept 和 entity 24 | self.concept_to_entity = defaultdict(set) 25 | for ent_id, ent_info in tqdm(self.entities.items()): 26 | self.name_to_id[ent_info['name']].append(ent_id) 27 | for c in self.get_all_concepts(ent_id): # merge entity into ancestor concept 28 | self.concept_to_entity[c].add(ent_id) 29 | self.concept_to_entity = { k:list(v) for k,v in self.concept_to_entity.items() } 30 | self.concepts = list(self.concept_to_entity.keys()) 31 | 32 | print('process attribute and relation') 33 | # get all attribute keys and relations 34 | self.attribute_keys = set() 35 | self.relations = set() 36 | self.key_type = {} 37 | ''' 38 | { 39 | : { 40 | : [idx1, idx2], # index in self.entities[ent_id]['attributes'] 41 | } 42 | } 43 | ''' 44 | 45 | self.attribute_inv_index = defaultdict(lambda: defaultdict(list)) 46 | # self.attribute_inv_index = {} 47 | ''' 48 | { 49 | (relation, direction): { 50 | : [idx1, idx2], # index in self.entities[ent_id]['relations'] 51 | } 52 | } 53 | ''' 54 | self.relation_inv_index = defaultdict(lambda: defaultdict(list)) 55 | # self.relation_inv_index = {} 56 | ''' 57 | { 58 | (sub_id, obj_id): [idx1, idx2] # index in self.entities[sub_id]['relations'] 59 | } 60 | ''' 61 | self.forward_relation_index = defaultdict(list) 62 | 63 | # store entities that have attribute 64 | self.entity_set_with_attribute = set() 65 | # store entities that have quantity attribute 66 | self.entity_set_with_quantity_attribute = set() 67 | # store entities that have attribute qualifier 68 | self.entity_set_with_attribute_qualifier = set() 69 | # store entities that have relation 70 | self.entity_set_with_relation = set() 71 | # store entities that have relation qualifier 72 | self.entity_set_with_relation_qualifier = set() 73 | for ent_id, ent_info in tqdm(self.entities.items()): 74 | for idx, attr_info in enumerate(ent_info['attributes']): 75 | self.attribute_keys.add(attr_info['key']) 76 | self.key_type[attr_info['key']] = attr_info['value']['type'] 77 | self.attribute_inv_index[attr_info['key']][ent_id].append(idx) 78 | self.entity_set_with_attribute.add(ent_id) 79 | if attr_info['value']['type'] == 'quantity': 80 | self.entity_set_with_quantity_attribute.add(ent_id) 81 | for qk in attr_info['qualifiers']: 82 | self.attribute_keys.add(qk) 83 | self.entity_set_with_attribute_qualifier.add(ent_id) 84 | for qv in attr_info['qualifiers'][qk]: 85 | self.key_type[qk] = qv['type'] 86 | 87 | for idx, rel_info in enumerate(ent_info['relations']): 88 | self.relations.add(rel_info['relation']) 89 | self.relation_inv_index[(rel_info['relation'], rel_info['direction'])][ent_id].append(idx) 90 | if rel_info['direction'] == 'forward': 91 | self.forward_relation_index[(ent_id, rel_info['object'])].append(idx) 92 | self.entity_set_with_relation.add(ent_id) 93 | for qk in rel_info['qualifiers']: 94 | self.attribute_keys.add(qk) 95 | self.entity_set_with_relation_qualifier.add(ent_id) 96 | for qv in rel_info['qualifiers'][qk]: 97 | self.key_type[qk] = qv['type'] 98 | 99 | # parse values into ValueClass object 100 | for attr_info in ent_info['attributes']: 101 | attr_info['value'] = self._parse_value(attr_info['value']) 102 | for qk, qvs in attr_info['qualifiers'].items(): 103 | attr_info['qualifiers'][qk] = [self._parse_value(qv) for qv in qvs] 104 | for rel_info in ent_info['relations']: 105 | for qk, qvs in rel_info['qualifiers'].items(): 106 | rel_info['qualifiers'][qk] = [self._parse_value(qv) for qv in qvs] 107 | 108 | self.attribute_keys = list(self.attribute_keys) 109 | self.relations = list(self.relations) 110 | # Note: key_type is one of string/quantity/date, but date means the key may have values of type year 111 | self.key_type = { k:v if v!='year' else 'date' for k,v in self.key_type.items() } 112 | self.entity_set_with_both_attribute_and_relation = list(self.entity_set_with_attribute & self.entity_set_with_relation) 113 | self.entity_set_with_attribute = list(self.entity_set_with_attribute) 114 | self.entity_set_with_quantity_attribute = list(self.entity_set_with_quantity_attribute) 115 | self.entity_set_with_attribute_qualifier = list(self.entity_set_with_attribute_qualifier) 116 | self.entity_set_with_relation = list(self.entity_set_with_relation) 117 | self.entity_set_with_relation_qualifier = list(self.entity_set_with_relation_qualifier) 118 | 119 | print('extract seen values') 120 | self.key_values = defaultdict(set) 121 | self.concept_key_values = defaultdict(lambda: defaultdict(set)) # not include qualifier values 122 | self.concept_relations = defaultdict(lambda: defaultdict(list)) 123 | 124 | for ent_id, ent_info in tqdm(self.entities.items()): 125 | for attr_info in ent_info['attributes']: 126 | k, v = attr_info['key'], attr_info['value'] 127 | self.key_values[k].add(v) 128 | for c in self.get_all_concepts(ent_id): 129 | self.concept_key_values[c][k].add(v) 130 | # merge qualifier statistics into attribute 131 | for qk, qvs in attr_info['qualifiers'].items(): 132 | for qv in qvs: 133 | self.key_values[qk].add(qv) 134 | 135 | for rel_info in ent_info['relations']: 136 | for c in self.get_all_concepts(ent_id): 137 | self.concept_relations[c][(rel_info['relation'], rel_info['direction'])].append(rel_info['object']) 138 | # merge qualifier statistics into attribute 139 | for qk, qvs in rel_info['qualifiers'].items(): 140 | for qv in qvs: 141 | self.key_values[qk].add(qv) 142 | for k in self.key_values: 143 | self.key_values[k] = list(self.key_values[k]) 144 | for c in self.concept_key_values: 145 | for k in self.concept_key_values[c]: 146 | self.concept_key_values[c][k] = list(self.concept_key_values[c][k]) 147 | 148 | print('number of concepts: %d' % len(self.concepts)) 149 | print('number of entities: %d' % len(self.entities)) 150 | print('number of attribute keys: %d' % len(self.attribute_keys)) 151 | print('number of relations: %d' % len(self.relations)) 152 | 153 | def get_direct_concepts(self, ent_id): 154 | """ 155 | return the direct concept id of given entity/concept 156 | """ 157 | if ent_id in self.entities: 158 | return [i for i in self.entities[ent_id]['isA'] if i in self.entities and i != ent_id] 159 | else: 160 | return [] 161 | # raise Exception('unknown id') 162 | 163 | def get_all_concepts(self, ent_id): 164 | """ 165 | return a concept id list 166 | """ 167 | ancestors = set() 168 | q = Queue() 169 | for c in self.get_direct_concepts(ent_id): 170 | q.put(c) 171 | while not q.empty(): 172 | con_id = q.get() 173 | if con_id in self.entities and con_id not in ancestors: # 防止循环祖先的情况 174 | ancestors.add(con_id) 175 | for c in self.entities[con_id]['isA']: 176 | q.put(c) 177 | ancestors = list(ancestors) 178 | return ancestors 179 | 180 | def print_statistics(self): 181 | cnt_rel, cnt_attr, cnt_qual = 0, 0, 0 182 | for ent_id, ent_info in self.entities.items(): 183 | for attr_info in ent_info['attributes']: 184 | cnt_attr += 1 185 | for qk in attr_info['qualifiers']: 186 | for qv in attr_info['qualifiers'][qk]: 187 | cnt_qual += 1 188 | for ent_id, ent_info in self.entities.items(): 189 | for rel_info in ent_info['relations']: 190 | cnt_rel += 1 191 | for qk in rel_info['qualifiers']: 192 | for qv in rel_info['qualifiers'][qk]: 193 | cnt_qual += 1 194 | 195 | print('number of relation knowledge: %d' % cnt_rel) 196 | print('number of attribute knowledge: %d' % cnt_attr) 197 | print('number of qualifier knowledge: %d' % cnt_qual) 198 | 199 | def _parse_value(self, value): 200 | if value['type'] == 'string': 201 | result = ValueClass('string', value['value']) 202 | elif value['type'] == 'quantity': 203 | result = ValueClass('quantity', (float)(value['value']), value['unit']) 204 | else: 205 | x = str(value['value']) 206 | if '/' in x or ('-' in x and '-' != x[0]): 207 | split_char = '/' if '/' in x else '-' 208 | p1, p2 = x.find(split_char), x.rfind(split_char) 209 | y, m, d = int(x[:p1]), int(x[p1+1:p2]), int(x[p2+1:]) 210 | result = ValueClass('date', date(y, m, d)) 211 | else: 212 | result = ValueClass('year', (int)(x)) 213 | return result -------------------------------------------------------------------------------- /doc/python/kopl/test/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THU-KEG/KoPL/486c07bd83ea32268ff90fa6942cc9f7e1574ae5/doc/python/kopl/test/__init__.py -------------------------------------------------------------------------------- /doc/python/kopl/util.py: -------------------------------------------------------------------------------- 1 | import json 2 | import os 3 | from collections import defaultdict 4 | from queue import Queue 5 | from datetime import date 6 | from tqdm import tqdm 7 | 8 | def comp(a, b, op): 9 | """ 10 | Args: 11 | - a (ValueClass): attribute value of a certain entity 12 | - b (ValueClass): comparison target 13 | - op: =/>/': 28 | return a > b 29 | elif op == '!=': 30 | return a != b 31 | else: 32 | raise TypeError('Unsupported operator. Support =/>/ other.value 114 | elif self.type == 'year': 115 | other_value = other.value if other.type == 'year' else other.value.year 116 | return self.value > other_value 117 | elif self.type == 'date': 118 | if other.type == 'year': 119 | return self.value.year > other.value 120 | else: 121 | return self.value > other.value 122 | 123 | def __str__(self): 124 | if self.type == 'string': 125 | return self.value 126 | elif self.type == 'quantity': 127 | if self.value - int(self.value) < 1e-5: 128 | v = int(self.value) 129 | else: 130 | v = self.value 131 | return '{} {}'.format(v, self.unit) if self.unit != '1' else str(v) 132 | elif self.type == 'year': 133 | return str(self.value) 134 | elif self.type == 'date': 135 | return self.value.isoformat() 136 | 137 | def __hash__(self): 138 | return hash(str(self)) -------------------------------------------------------------------------------- /doc/source/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THU-KEG/KoPL/486c07bd83ea32268ff90fa6942cc9f7e1574ae5/doc/source/.DS_Store -------------------------------------------------------------------------------- /doc/source/0_intro.rst: -------------------------------------------------------------------------------- 1 | 面向复杂推理问答的程序表示——KoPL 2 | ================================================================ 3 | 4 | KoPL全称 Knowledge oriented Programing Language,是一个为复杂推理问答而设计的面向知识的编程语言。KoPL可以将自然语言问题表示为由27个基本函数组合而成的KoPL程序,程序运行的结果就是问题的答案。目前,KoPL的27个基本函数覆盖对多种知识元素(如概念、实体、关系、属性、修饰符等)的操作,并支持多种问题类型(如计数、事实验证、比较等)的查询。KoPL提供透明的复杂问题推理过程,易于理解和使用。 5 | 6 | KoPL的设计理念为: 7 | 8 | - 显式、透明的推理过程 9 | - 易于理解,便于人机交互 10 | - 面向知识库、文本等不同形式的知识,可扩展性强 11 | -------------------------------------------------------------------------------- /doc/source/1_knowledge.rst: -------------------------------------------------------------------------------- 1 | ====================== 2 | KoPL面向的知识元素 3 | ====================== 4 | 5 | .. image:: knowledge_element.jpg 6 | :width: 600 7 | :alt: Alternative text 8 | 9 | 使用KoPL的前提是要有一个合适的目标知识库,该知识库中应该含有如下元素: 10 | 11 | - 实体(Entity) 12 | - 概念(Concept) 13 | - 关系(Relation) 14 | - 属性(Attribute) 15 | - 关系型知识(Relational Knowledge) 16 | - 属性型知识(LiteralKnowledge) 17 | - 修饰型知识(Qualifier Knowledge) 18 | 19 | 实体 20 | ----------------- 21 | 22 | .. glossary:: 23 | 24 | 知识库中最基本的元素,用来表示一个独一无二的事物。 25 | 26 | .. admonition:: 例子 27 | 28 | 勒布朗·詹姆斯(Lebron James)和克利夫兰骑士队(Cleveland Cavaliers)都是实体。 29 | 30 | 概念 31 | ----------------- 32 | 33 | .. glossary:: 34 | 35 | 一组具有相同特征的实体组成的集合。 36 | 37 | .. admonition:: 例子 38 | 39 | 篮球队(Basketball Team)便是一个概念。 40 | 41 | 关系 42 | ----------------- 43 | 44 | .. glossary:: 45 | 46 | 表示两个实体之间的关系。特殊地,实体通过 instance of 关系链接到相应的概念上,概念之间通过 subclass of 关系来组织成层次结构。 47 | 48 | .. admonition:: 例子 49 | 50 | 父亲(father)和出生地(place of birth)都是关系。 51 | 52 | 属性 53 | ----------------- 54 | 55 | .. glossary:: 56 | 57 | 表示实体的属性信息。又由属性键和属性值两部分组成,属性值有字符串、数字、日期和年份4种类型。其中数值类型的属性值又包含单位,如“206厘米”中的“厘米”。 58 | 59 | .. admonition:: 例子 60 | 61 | 身高(height)是一个属性,206厘米是对应的属性值。 62 | 63 | 关系型知识 64 | ----------------- 65 | 66 | .. glossary:: 67 | 68 | 用于表示两个实体间关系的三元组, 由(实体,关系,实体)组成。 69 | 70 | .. admonition:: 例子 71 | 72 | (勒布朗·詹姆斯,出生地,阿克伦)是一个关系型知识。 73 | 74 | 属性型知识 75 | ----------------- 76 | 77 | .. glossary:: 78 | 79 | 用于表示一个实体属性信息的三元组,由(实体,属性键,属性值)组成。 80 | 81 | .. admonition:: 例子 82 | 83 | (勒布朗·詹姆斯,身高,206厘米)是一个属性型知识。 84 | 85 | 修饰型知识 86 | ----------------- 87 | 88 | .. glossary:: 89 | 90 | 用于对一个关系型或属性型的三元组进行进一步的修饰,包含一个修饰键和一个修饰值。由(三元组,修饰键,修饰值)组成。 91 | 92 | .. admonition:: 例子 93 | 94 | ((勒布朗·詹姆斯,被选球队,克利夫兰骑士队),选择时间,2003年)是一个修饰型知识。 -------------------------------------------------------------------------------- /doc/source/3_install.rst: -------------------------------------------------------------------------------- 1 | 安装 2 | ============ 3 | 4 | KoPL支持Linux (e.g., Ubuntu/CentOS),macOS,Windows。 5 | 6 | 其依赖为: 7 | 8 | :: 9 | 10 | python >= 3.6 11 | 12 | tqdm >= 4.62 13 | 14 | 15 | KoPL提供pip安装, 下面将展示Ubuntu的安装命令: 16 | 17 | :: 18 | 19 | $ pip install KoPL 20 | 21 | 运行下面的代码 22 | 23 | :: 24 | 25 | import kopl 26 | from kopl.test.test_example import * 27 | run_test() 28 | 29 | 如果测试运行通过,恭喜您已经安装成功。 30 | -------------------------------------------------------------------------------- /doc/source/4_helloworld.rst: -------------------------------------------------------------------------------- 1 | 第一个KoPL程序 2 | ============ 3 | 4 | 5 | 准备知识库 6 | ----------------- 7 | 8 | 目前,我们支持JSON格式的知识库,其形式为: 9 | 10 | :: 11 | 12 | { 13 | # 概念 14 | 'concepts': { 15 | 'id': { 16 | 'name': '', 17 | 'subclassOf': [''], 18 | } 19 | }, 20 | # 实体,确保与概念是不相交的 21 | 'entities': { 22 | 'id': { 23 | 'name': '', 24 | 'instanceOf': [''], 25 | 'attributes': [ 26 | { 27 | 'key': '', 28 | 'value': { 29 | 'type': 'string'/'quantity'/'date'/'year' 30 | 'value': # quantity类型为float或int, year类型为int, date类型为'yyyy/mm/dd' 31 | 'unit': # 针对quantity类型,为str, 如'height'的unit可以是'centimetre', ‘population’的unit是‘1’ 32 | }, 33 | 'qualifiers': { 34 | '': [ 35 | , # 每个qv都是像'value'一样的字典,包括'type', 'value'和'int' 36 | ] 37 | } 38 | } 39 | ] 40 | 'relations': [ 41 | { 42 | 'relation': '', 43 | 'direction': 'forward' or 'backward', 44 | 'object': '', 45 | 'qualifiers': { 46 | '': [ 47 | , # 每个qv都是像'value'一样的字典,包括'type', 'value'和'int' 48 | ] 49 | } 50 | } 51 | ] 52 | } 53 | } 54 | } 55 | 56 | .. image:: knowledge_element.jpg 57 | :width: 600 58 | :alt: Alternative text 59 | 60 | 例如,对于上图中的知识库,知识库为: 61 | 62 | :: 63 | 64 | example_kb = { 65 | 'concepts': { 66 | 'Q13393265': { 67 | 'name': 'basketball team', 68 | 'subclassOf': ['Q12973014'] 69 | }, 70 | 'Q12973014': { 71 | 'name': 'sports team', 72 | 'subclassOf': [] 73 | }, 74 | 'Q3665646': { 75 | 'name': 'basketball player', 76 | 'subclassOf': ['Q2066131'] 77 | }, 78 | 'Q2066131': { 79 | 'name': 'athlete', 80 | 'subclassOf': [] 81 | } 82 | }, 83 | 'entities': { 84 | 'Q36159': { 85 | 'name': 'LeBron James', 86 | 'instanceOf': ['Q3665646'], 87 | 'attributes': [ 88 | { 89 | 'key': 'height', 90 | 'value': { 91 | 'type': 'quantity', 92 | 'value': 206, 93 | 'unit': 'centimetre' 94 | }, 95 | 'qualifiers': {} 96 | }, 97 | { 98 | 'key': 'work period (start)', 99 | 'value': { 100 | 'type': 'year', 101 | 'value': 2003 102 | }, 103 | 'qualifiers': {} 104 | }, 105 | { 106 | 'key': 'sex or gender', 107 | 'value': { 108 | 'type': 'string', 109 | 'value': 'male' 110 | }, 111 | 'qualifiers': {} 112 | }, 113 | { 114 | 'key': 'date of birth', 115 | 'value': { 116 | 'type': 'date', 117 | 'value': '1984-12-30' 118 | }, 119 | 'qualifiers': {} 120 | } 121 | ], 122 | 'relations': [ 123 | { 124 | 'relation': 'place of birth', 125 | 'direction': 'forward', 126 | 'object': 'Q163132', 127 | 'qualifiers': {} 128 | }, 129 | { 130 | 'relation': 'drafted by', 131 | 'direction': 'forward', 132 | 'object': 'Q162990', 133 | 'qualifiers': { 134 | 'point in time': [ 135 | { 136 | 'type': 'date', 137 | 'value': '2003-06-26' 138 | } 139 | ] 140 | } 141 | }, 142 | { 143 | 'relation': 'child', 144 | 'direction': 'forward', 145 | 'object': 'Q22302425', 146 | 'qualifiers': {} 147 | 148 | }, 149 | { 150 | 'relation': 'member of sports team', 151 | 'direction': 'forward', 152 | 'object': 'Q162990', 153 | 'qualifiers': { 154 | 'position played on team/speciality': [ 155 | { 156 | 'type': 'string', 157 | 'value': 'small forward' 158 | } 159 | ], 160 | 'sport number': [ 161 | { 162 | 'type': 'quantity', 163 | 'value': 23, 164 | 'unit': '1' 165 | } 166 | ] 167 | } 168 | } 169 | ] 170 | }, 171 | 'Q163132': { 172 | 'name': 'Akron', 173 | 'instanceOf': [], 174 | 'attributes': [ 175 | { 176 | 'key': 'population', 177 | 'value': { 178 | 'type': 'quantity', 179 | 'value': 199110, 180 | 'unit': '1' 181 | }, 182 | 'qualifiers': { 183 | 'point in time': [ 184 | { 185 | 'type': 'year', 186 | 'value': 2010 187 | } 188 | ] 189 | } 190 | } 191 | ], 192 | 'relations': [] 193 | }, 194 | 'Q162990': { 195 | 'name': 'Cleveland Cavaliers', 196 | 'instanceOf': ['Q13393265'], 197 | 'attributes': [ 198 | { 199 | 'key': 'inception', 200 | 'value': { 201 | 'type': 'year', 202 | 'value': 1970 203 | }, 204 | 'qualifiers': {} 205 | } 206 | ], 207 | 'relations': [] 208 | }, 209 | 'Q22302425': { 210 | 'name': 'LeBron James Jr.', 211 | 'instanceOf': ['Q3665646'], 212 | 'attributes': [ 213 | { 214 | 'key': 'height', 215 | 'value': { 216 | 'type': 'quantity', 217 | 'value': 188, 218 | 'unit': 'centimetre' 219 | }, 220 | 'qualifiers': {} 221 | }, 222 | { 223 | 'key': 'sex or gender', 224 | 'value': { 225 | 'type': 'string', 226 | 'value': 'male' 227 | }, 228 | 'qualifiers': {} 229 | }, 230 | { 231 | 'key': 'date of birth', 232 | 'value': { 233 | 'type': 'date', 234 | 'value': '2004-10-06' 235 | }, 236 | 'qualifiers': {} 237 | } 238 | ], 239 | 'relations': [ 240 | { 241 | 'relation': 'father', 242 | 'direction': 'forward', 243 | 'object': 'Q36159', 244 | 'qualifiers': {} 245 | } 246 | ] 247 | 248 | } 249 | } 250 | 251 | } 252 | 253 | 254 | KoPL编程问答 255 | ---------------------------- 256 | 257 | KoPL的实现基于python,此处演示一个示例。更多API请参考API文档 258 | :doc:`7_kopl`,关于KoPL基本函数的介绍可以参考 259 | :doc:`2_function`。 260 | 261 | :: 262 | 263 | from kopl.kopl import KoPLEngine 264 | from kopl.test.test_example import example_kb 265 | 266 | engine = KoPLEngine(example_kb) 267 | 268 | ans = engine.SelectBetween( 269 | engine.Find('LeBron James Jr.'), 270 | engine.Relate( 271 | engine.Find('LeBron James Jr.'), 272 | 'father', 273 | 'forward' 274 | ), 275 | 'height', 276 | 'greater' 277 | ) 278 | 279 | print(ans) 280 | 281 | 在这个示例里,我们查询LeBron James Jr.和他的父亲谁更高,KoPL程序给出了正确的答案: LeBron James! 282 | 283 | 284 | 更多KoPL样例请参考 285 | :doc:`更多KoPL样例 <5_example>`。 286 | 287 | -------------------------------------------------------------------------------- /doc/source/6_service.rst: -------------------------------------------------------------------------------- 1 | 查询服务 2 | ============================================================================ 3 | 4 | 您可以准备自己的知识库,搭建自己的KoPL引擎来实现复杂推理问答,也可以使用我们为您提供的 `查询服务 `_ ,快速开启KoPL之旅~ 5 | 6 | 我们的查询引擎基于 `Wikidata15k `_ , 查询示例可以参考 7 | :doc:`更多KoPL样例 <5_example>`。 -------------------------------------------------------------------------------- /doc/source/7_kopl.rst: -------------------------------------------------------------------------------- 1 | KoPL引擎 2 | =========== 3 | 4 | .. automodule:: kopl.kopl 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /doc/source/_build/doctrees/0_intro.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THU-KEG/KoPL/486c07bd83ea32268ff90fa6942cc9f7e1574ae5/doc/source/_build/doctrees/0_intro.doctree -------------------------------------------------------------------------------- /doc/source/_build/doctrees/1_knowledge.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THU-KEG/KoPL/486c07bd83ea32268ff90fa6942cc9f7e1574ae5/doc/source/_build/doctrees/1_knowledge.doctree -------------------------------------------------------------------------------- /doc/source/_build/doctrees/2_function.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THU-KEG/KoPL/486c07bd83ea32268ff90fa6942cc9f7e1574ae5/doc/source/_build/doctrees/2_function.doctree -------------------------------------------------------------------------------- /doc/source/_build/doctrees/3_install.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THU-KEG/KoPL/486c07bd83ea32268ff90fa6942cc9f7e1574ae5/doc/source/_build/doctrees/3_install.doctree -------------------------------------------------------------------------------- /doc/source/_build/doctrees/4_helloworld.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THU-KEG/KoPL/486c07bd83ea32268ff90fa6942cc9f7e1574ae5/doc/source/_build/doctrees/4_helloworld.doctree -------------------------------------------------------------------------------- /doc/source/_build/doctrees/5_example.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THU-KEG/KoPL/486c07bd83ea32268ff90fa6942cc9f7e1574ae5/doc/source/_build/doctrees/5_example.doctree -------------------------------------------------------------------------------- /doc/source/_build/doctrees/6_service.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THU-KEG/KoPL/486c07bd83ea32268ff90fa6942cc9f7e1574ae5/doc/source/_build/doctrees/6_service.doctree -------------------------------------------------------------------------------- /doc/source/_build/doctrees/7_kopl.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THU-KEG/KoPL/486c07bd83ea32268ff90fa6942cc9f7e1574ae5/doc/source/_build/doctrees/7_kopl.doctree -------------------------------------------------------------------------------- /doc/source/_build/doctrees/environment.pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THU-KEG/KoPL/486c07bd83ea32268ff90fa6942cc9f7e1574ae5/doc/source/_build/doctrees/environment.pickle -------------------------------------------------------------------------------- /doc/source/_build/doctrees/index.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THU-KEG/KoPL/486c07bd83ea32268ff90fa6942cc9f7e1574ae5/doc/source/_build/doctrees/index.doctree -------------------------------------------------------------------------------- /doc/source/_build/html/.buildinfo: -------------------------------------------------------------------------------- 1 | # Sphinx build info version 1 2 | # This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done. 3 | config: 646a145bcf8c7dd65b61aa7cc9610e90 4 | tags: 645f666f9bcd5a90fca523b33c5a78b7 5 | -------------------------------------------------------------------------------- /doc/source/_build/html/.doctrees/0_intro.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THU-KEG/KoPL/486c07bd83ea32268ff90fa6942cc9f7e1574ae5/doc/source/_build/html/.doctrees/0_intro.doctree -------------------------------------------------------------------------------- /doc/source/_build/html/.doctrees/1_knowledge.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THU-KEG/KoPL/486c07bd83ea32268ff90fa6942cc9f7e1574ae5/doc/source/_build/html/.doctrees/1_knowledge.doctree -------------------------------------------------------------------------------- /doc/source/_build/html/.doctrees/2_function.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THU-KEG/KoPL/486c07bd83ea32268ff90fa6942cc9f7e1574ae5/doc/source/_build/html/.doctrees/2_function.doctree -------------------------------------------------------------------------------- /doc/source/_build/html/.doctrees/3_install.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THU-KEG/KoPL/486c07bd83ea32268ff90fa6942cc9f7e1574ae5/doc/source/_build/html/.doctrees/3_install.doctree -------------------------------------------------------------------------------- /doc/source/_build/html/.doctrees/4_helloworld.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THU-KEG/KoPL/486c07bd83ea32268ff90fa6942cc9f7e1574ae5/doc/source/_build/html/.doctrees/4_helloworld.doctree -------------------------------------------------------------------------------- /doc/source/_build/html/.doctrees/5_example.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THU-KEG/KoPL/486c07bd83ea32268ff90fa6942cc9f7e1574ae5/doc/source/_build/html/.doctrees/5_example.doctree -------------------------------------------------------------------------------- /doc/source/_build/html/.doctrees/6_service.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THU-KEG/KoPL/486c07bd83ea32268ff90fa6942cc9f7e1574ae5/doc/source/_build/html/.doctrees/6_service.doctree -------------------------------------------------------------------------------- /doc/source/_build/html/.doctrees/7_kopl.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THU-KEG/KoPL/486c07bd83ea32268ff90fa6942cc9f7e1574ae5/doc/source/_build/html/.doctrees/7_kopl.doctree -------------------------------------------------------------------------------- /doc/source/_build/html/.doctrees/doc_1_knowledge.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THU-KEG/KoPL/486c07bd83ea32268ff90fa6942cc9f7e1574ae5/doc/source/_build/html/.doctrees/doc_1_knowledge.doctree -------------------------------------------------------------------------------- /doc/source/_build/html/.doctrees/doc_2_function.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THU-KEG/KoPL/486c07bd83ea32268ff90fa6942cc9f7e1574ae5/doc/source/_build/html/.doctrees/doc_2_function.doctree -------------------------------------------------------------------------------- /doc/source/_build/html/.doctrees/doc_3_engine.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THU-KEG/KoPL/486c07bd83ea32268ff90fa6942cc9f7e1574ae5/doc/source/_build/html/.doctrees/doc_3_engine.doctree -------------------------------------------------------------------------------- /doc/source/_build/html/.doctrees/doc_4_example.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THU-KEG/KoPL/486c07bd83ea32268ff90fa6942cc9f7e1574ae5/doc/source/_build/html/.doctrees/doc_4_example.doctree -------------------------------------------------------------------------------- /doc/source/_build/html/.doctrees/environment.pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THU-KEG/KoPL/486c07bd83ea32268ff90fa6942cc9f7e1574ae5/doc/source/_build/html/.doctrees/environment.pickle -------------------------------------------------------------------------------- /doc/source/_build/html/.doctrees/exam_1_input.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THU-KEG/KoPL/486c07bd83ea32268ff90fa6942cc9f7e1574ae5/doc/source/_build/html/.doctrees/exam_1_input.doctree -------------------------------------------------------------------------------- /doc/source/_build/html/.doctrees/exam_2_schema.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THU-KEG/KoPL/486c07bd83ea32268ff90fa6942cc9f7e1574ae5/doc/source/_build/html/.doctrees/exam_2_schema.doctree -------------------------------------------------------------------------------- /doc/source/_build/html/.doctrees/example.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THU-KEG/KoPL/486c07bd83ea32268ff90fa6942cc9f7e1574ae5/doc/source/_build/html/.doctrees/example.doctree -------------------------------------------------------------------------------- /doc/source/_build/html/.doctrees/function.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THU-KEG/KoPL/486c07bd83ea32268ff90fa6942cc9f7e1574ae5/doc/source/_build/html/.doctrees/function.doctree -------------------------------------------------------------------------------- /doc/source/_build/html/.doctrees/glossary.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THU-KEG/KoPL/486c07bd83ea32268ff90fa6942cc9f7e1574ae5/doc/source/_build/html/.doctrees/glossary.doctree -------------------------------------------------------------------------------- /doc/source/_build/html/.doctrees/helloworld.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THU-KEG/KoPL/486c07bd83ea32268ff90fa6942cc9f7e1574ae5/doc/source/_build/html/.doctrees/helloworld.doctree -------------------------------------------------------------------------------- /doc/source/_build/html/.doctrees/index.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THU-KEG/KoPL/486c07bd83ea32268ff90fa6942cc9f7e1574ae5/doc/source/_build/html/.doctrees/index.doctree -------------------------------------------------------------------------------- /doc/source/_build/html/.doctrees/install.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THU-KEG/KoPL/486c07bd83ea32268ff90fa6942cc9f7e1574ae5/doc/source/_build/html/.doctrees/install.doctree -------------------------------------------------------------------------------- /doc/source/_build/html/.doctrees/intro.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THU-KEG/KoPL/486c07bd83ea32268ff90fa6942cc9f7e1574ae5/doc/source/_build/html/.doctrees/intro.doctree -------------------------------------------------------------------------------- /doc/source/_build/html/.doctrees/knowledge.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THU-KEG/KoPL/486c07bd83ea32268ff90fa6942cc9f7e1574ae5/doc/source/_build/html/.doctrees/knowledge.doctree -------------------------------------------------------------------------------- /doc/source/_build/html/.doctrees/kopl.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THU-KEG/KoPL/486c07bd83ea32268ff90fa6942cc9f7e1574ae5/doc/source/_build/html/.doctrees/kopl.doctree -------------------------------------------------------------------------------- /doc/source/_build/html/.doctrees/quick_start.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THU-KEG/KoPL/486c07bd83ea32268ff90fa6942cc9f7e1574ae5/doc/source/_build/html/.doctrees/quick_start.doctree -------------------------------------------------------------------------------- /doc/source/_build/html/.doctrees/schema.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THU-KEG/KoPL/486c07bd83ea32268ff90fa6942cc9f7e1574ae5/doc/source/_build/html/.doctrees/schema.doctree -------------------------------------------------------------------------------- /doc/source/_build/html/.doctrees/service.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THU-KEG/KoPL/486c07bd83ea32268ff90fa6942cc9f7e1574ae5/doc/source/_build/html/.doctrees/service.doctree -------------------------------------------------------------------------------- /doc/source/_build/html/0_intro.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 面向复杂推理问答的程序表示——KoPL — KoPL 1.0.0 documentation 7 | 8 | 9 | 10 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 68 | 69 |
73 | 74 |
75 |
76 |
77 |
    78 |
  • »
  • 79 |
  • 面向复杂推理问答的程序表示——KoPL
  • 80 |
  • 81 |
  • 82 |
83 |
84 |
85 |
86 |
87 | 88 |
89 |

面向复杂推理问答的程序表示——KoPL

90 |

KoPL全称 Knowledge oriented Programing Language,是一个为复杂推理问答而设计的面向知识的编程语言。KoPL可以将自然语言问题表示为由27个基本函数组合而成的KoPL程序,程序运行的结果就是问题的答案。目前,KoPL的27个基本函数覆盖对多种知识元素(如概念、实体、关系、属性、修饰符等)的操作,并支持多种问题类型(如计数、事实验证、比较等)的查询。KoPL提供透明的复杂问题推理过程,易于理解和使用。

91 |

KoPL的设计理念为:

92 |
    93 |
  • 显式、透明的推理过程

  • 94 |
  • 易于理解,便于人机交互

  • 95 |
  • 面向知识库、文本等不同形式的知识,可扩展性强

  • 96 |
97 |
98 | 99 | 100 |
101 |
102 |
106 | 107 |
108 | 109 |
110 |

© Copyright 2021, KEG.

111 |
112 | 113 | Built with Sphinx using a 114 | theme 115 | provided by Read the Docs. 116 | 117 | 118 |
119 |
120 |
121 |
122 |
123 | 128 | 129 | 130 | -------------------------------------------------------------------------------- /doc/source/_build/html/3_install.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 安装 — KoPL 1.0.0 documentation 7 | 8 | 9 | 10 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 68 | 69 |
73 | 74 |
75 |
76 |
77 |
    78 |
  • »
  • 79 |
  • 安装
  • 80 |
  • 81 |
  • 82 |
83 |
84 |
85 |
86 |
87 | 88 |
89 |

安装

90 |

KoPL支持Linux (e.g., Ubuntu/CentOS),macOS,Windows。

91 |

其依赖为:

92 |
python >= 3.6
 93 | 
 94 | tqdm >= 4.62
 95 | 
96 |
97 |

KoPL提供pip安装, 下面将展示Ubuntu的安装命令:

98 |
$ pip install KoPL
 99 | 
100 |
101 |

运行下面的代码

102 |
import kopl
103 | from kopl.test.test_example import *
104 | run_test()
105 | 
106 |
107 |

如果测试运行通过,恭喜您已经安装成功。

108 |
109 | 110 | 111 |
112 |
113 |
117 | 118 |
119 | 120 |
121 |

© Copyright 2021, KEG.

122 |
123 | 124 | Built with Sphinx using a 125 | theme 126 | provided by Read the Docs. 127 | 128 | 129 |
130 |
131 |
132 |
133 |
134 | 139 | 140 | 141 | -------------------------------------------------------------------------------- /doc/source/_build/html/6_service.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 查询服务 — KoPL 1.0.0 documentation 7 | 8 | 9 | 10 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 68 | 69 |
73 | 74 |
75 |
76 |
77 |
    78 |
  • »
  • 79 |
  • 查询服务
  • 80 |
  • 81 |
  • 82 |
83 |
84 |
85 |
86 |
87 | 88 |
89 |

查询服务

90 |

您可以准备自己的知识库,搭建自己的KoPL引擎来实现复杂推理问答,也可以使用我们为您提供的 查询服务 ,快速开启KoPL之旅~

91 |

我们的查询引擎基于 Wikidata15k , 查询示例可以参考 92 | 更多KoPL样例

93 |
94 | 95 | 96 |
97 |
98 |
102 | 103 |
104 | 105 |
106 |

© Copyright 2021, KEG.

107 |
108 | 109 | Built with Sphinx using a 110 | theme 111 | provided by Read the Docs. 112 | 113 | 114 |
115 |
116 |
117 |
118 |
119 | 124 | 125 | 126 | -------------------------------------------------------------------------------- /doc/source/_build/html/_images/demo1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THU-KEG/KoPL/486c07bd83ea32268ff90fa6942cc9f7e1574ae5/doc/source/_build/html/_images/demo1.png -------------------------------------------------------------------------------- /doc/source/_build/html/_images/demo10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THU-KEG/KoPL/486c07bd83ea32268ff90fa6942cc9f7e1574ae5/doc/source/_build/html/_images/demo10.png -------------------------------------------------------------------------------- /doc/source/_build/html/_images/demo11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THU-KEG/KoPL/486c07bd83ea32268ff90fa6942cc9f7e1574ae5/doc/source/_build/html/_images/demo11.png -------------------------------------------------------------------------------- /doc/source/_build/html/_images/demo12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THU-KEG/KoPL/486c07bd83ea32268ff90fa6942cc9f7e1574ae5/doc/source/_build/html/_images/demo12.png -------------------------------------------------------------------------------- /doc/source/_build/html/_images/demo13.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THU-KEG/KoPL/486c07bd83ea32268ff90fa6942cc9f7e1574ae5/doc/source/_build/html/_images/demo13.png -------------------------------------------------------------------------------- /doc/source/_build/html/_images/demo2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THU-KEG/KoPL/486c07bd83ea32268ff90fa6942cc9f7e1574ae5/doc/source/_build/html/_images/demo2.png -------------------------------------------------------------------------------- /doc/source/_build/html/_images/demo3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THU-KEG/KoPL/486c07bd83ea32268ff90fa6942cc9f7e1574ae5/doc/source/_build/html/_images/demo3.png -------------------------------------------------------------------------------- /doc/source/_build/html/_images/demo4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THU-KEG/KoPL/486c07bd83ea32268ff90fa6942cc9f7e1574ae5/doc/source/_build/html/_images/demo4.png -------------------------------------------------------------------------------- /doc/source/_build/html/_images/demo5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THU-KEG/KoPL/486c07bd83ea32268ff90fa6942cc9f7e1574ae5/doc/source/_build/html/_images/demo5.png -------------------------------------------------------------------------------- /doc/source/_build/html/_images/demo6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THU-KEG/KoPL/486c07bd83ea32268ff90fa6942cc9f7e1574ae5/doc/source/_build/html/_images/demo6.png -------------------------------------------------------------------------------- /doc/source/_build/html/_images/demo7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THU-KEG/KoPL/486c07bd83ea32268ff90fa6942cc9f7e1574ae5/doc/source/_build/html/_images/demo7.png -------------------------------------------------------------------------------- /doc/source/_build/html/_images/demo8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THU-KEG/KoPL/486c07bd83ea32268ff90fa6942cc9f7e1574ae5/doc/source/_build/html/_images/demo8.png -------------------------------------------------------------------------------- /doc/source/_build/html/_images/demo9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THU-KEG/KoPL/486c07bd83ea32268ff90fa6942cc9f7e1574ae5/doc/source/_build/html/_images/demo9.png -------------------------------------------------------------------------------- /doc/source/_build/html/_images/knowledge_element.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THU-KEG/KoPL/486c07bd83ea32268ff90fa6942cc9f7e1574ae5/doc/source/_build/html/_images/knowledge_element.jpg -------------------------------------------------------------------------------- /doc/source/_build/html/_modules/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Overview: module code — KoPL 1.0.0 documentation 7 | 8 | 9 | 10 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 66 | 67 |
71 | 72 |
73 |
74 |
75 |
    76 |
  • »
  • 77 |
  • Overview: module code
  • 78 |
  • 79 |
  • 80 |
81 |
82 |
83 |
84 |
85 | 86 |

All modules for which code is available

87 | 89 | 90 |
91 |
92 |
93 | 94 |
95 | 96 |
97 |

© Copyright 2021, KEG.

98 |
99 | 100 | Built with Sphinx using a 101 | theme 102 | provided by Read the Docs. 103 | 104 | 105 |
106 |
107 |
108 |
109 |
110 | 115 | 116 | 117 | -------------------------------------------------------------------------------- /doc/source/_build/html/_sources/0_intro.rst.txt: -------------------------------------------------------------------------------- 1 | 面向复杂推理问答的程序表示——KoPL 2 | ================================================================ 3 | 4 | KoPL全称 Knowledge oriented Programing Language,是一个为复杂推理问答而设计的面向知识的编程语言。KoPL可以将自然语言问题表示为由27个基本函数组合而成的KoPL程序,程序运行的结果就是问题的答案。目前,KoPL的27个基本函数覆盖对多种知识元素(如概念、实体、关系、属性、修饰符等)的操作,并支持多种问题类型(如计数、事实验证、比较等)的查询。KoPL提供透明的复杂问题推理过程,易于理解和使用。 5 | 6 | KoPL的设计理念为: 7 | 8 | - 显式、透明的推理过程 9 | - 易于理解,便于人机交互 10 | - 面向知识库、文本等不同形式的知识,可扩展性强 11 | -------------------------------------------------------------------------------- /doc/source/_build/html/_sources/1_knowledge.rst.txt: -------------------------------------------------------------------------------- 1 | ====================== 2 | KoPL面向的知识元素 3 | ====================== 4 | 5 | .. image:: knowledge_element.jpg 6 | :width: 600 7 | :alt: Alternative text 8 | 9 | 使用KoPL的前提是要有一个合适的目标知识库,该知识库中应该含有如下元素: 10 | 11 | - 实体(Entity) 12 | - 概念(Concept) 13 | - 关系(Relation) 14 | - 属性(Attribute) 15 | - 关系型知识(Relational Knowledge) 16 | - 属性型知识(LiteralKnowledge) 17 | - 修饰型知识(Qualifier Knowledge) 18 | 19 | 实体 20 | ----------------- 21 | 22 | .. glossary:: 23 | 24 | 知识库中最基本的元素,用来表示一个独一无二的事物。 25 | 26 | .. admonition:: 例子 27 | 28 | 勒布朗·詹姆斯(Lebron James)和克利夫兰骑士队(Cleveland Cavaliers)都是实体。 29 | 30 | 概念 31 | ----------------- 32 | 33 | .. glossary:: 34 | 35 | 一组具有相同特征的实体组成的集合。 36 | 37 | .. admonition:: 例子 38 | 39 | 篮球队(Basketball Team)便是一个概念。 40 | 41 | 关系 42 | ----------------- 43 | 44 | .. glossary:: 45 | 46 | 表示两个实体之间的关系。特殊地,实体通过 instance of 关系链接到相应的概念上,概念之间通过 subclass of 关系来组织成层次结构。 47 | 48 | .. admonition:: 例子 49 | 50 | 父亲(father)和出生地(place of birth)都是关系。 51 | 52 | 属性 53 | ----------------- 54 | 55 | .. glossary:: 56 | 57 | 表示实体的属性信息。又由属性键和属性值两部分组成,属性值有字符串、数字、日期和年份4种类型。其中数值类型的属性值又包含单位,如“206厘米”中的“厘米”。 58 | 59 | .. admonition:: 例子 60 | 61 | 身高(height)是一个属性,206厘米是对应的属性值。 62 | 63 | 关系型知识 64 | ----------------- 65 | 66 | .. glossary:: 67 | 68 | 用于表示两个实体间关系的三元组, 由(实体,关系,实体)组成。 69 | 70 | .. admonition:: 例子 71 | 72 | (勒布朗·詹姆斯,出生地,阿克伦)是一个关系型知识。 73 | 74 | 属性型知识 75 | ----------------- 76 | 77 | .. glossary:: 78 | 79 | 用于表示一个实体属性信息的三元组,由(实体,属性键,属性值)组成。 80 | 81 | .. admonition:: 例子 82 | 83 | (勒布朗·詹姆斯,身高,206厘米)是一个属性型知识。 84 | 85 | 修饰型知识 86 | ----------------- 87 | 88 | .. glossary:: 89 | 90 | 用于对一个关系型或属性型的三元组进行进一步的修饰,包含一个修饰键和一个修饰值。由(三元组,修饰键,修饰值)组成。 91 | 92 | .. admonition:: 例子 93 | 94 | ((勒布朗·詹姆斯,被选球队,克利夫兰骑士队),选择时间,2003年)是一个修饰型知识。 -------------------------------------------------------------------------------- /doc/source/_build/html/_sources/3_install.rst.txt: -------------------------------------------------------------------------------- 1 | 安装 2 | ============ 3 | 4 | KoPL支持Linux (e.g., Ubuntu/CentOS),macOS,Windows。 5 | 6 | 其依赖为: 7 | 8 | :: 9 | 10 | python >= 3.6 11 | 12 | tqdm >= 4.62 13 | 14 | 15 | KoPL提供pip安装, 下面将展示Ubuntu的安装命令: 16 | 17 | :: 18 | 19 | $ pip install KoPL 20 | 21 | 运行下面的代码 22 | 23 | :: 24 | 25 | import kopl 26 | from kopl.test.test_example import * 27 | run_test() 28 | 29 | 如果测试运行通过,恭喜您已经安装成功。 30 | -------------------------------------------------------------------------------- /doc/source/_build/html/_sources/4_helloworld.rst.txt: -------------------------------------------------------------------------------- 1 | 第一个KoPL程序 2 | ============ 3 | 4 | 5 | 准备知识库 6 | ----------------- 7 | 8 | 目前,我们支持JSON格式的知识库,其形式为: 9 | 10 | :: 11 | 12 | { 13 | # 概念 14 | 'concepts': { 15 | 'id': { 16 | 'name': '', 17 | 'subclassOf': [''], 18 | } 19 | }, 20 | # 实体,确保与概念是不相交的 21 | 'entities': { 22 | 'id': { 23 | 'name': '', 24 | 'instanceOf': [''], 25 | 'attributes': [ 26 | { 27 | 'key': '', 28 | 'value': { 29 | 'type': 'string'/'quantity'/'date'/'year' 30 | 'value': # quantity类型为float或int, year类型为int, date类型为'yyyy/mm/dd' 31 | 'unit': # 针对quantity类型,为str, 如'height'的unit可以是'centimetre', ‘population’的unit是‘1’ 32 | }, 33 | 'qualifiers': { 34 | '': [ 35 | , # 每个qv都是像'value'一样的字典,包括'type', 'value'和'int' 36 | ] 37 | } 38 | } 39 | ] 40 | 'relations': [ 41 | { 42 | 'relation': '', 43 | 'direction': 'forward' or 'backward', 44 | 'object': '', 45 | 'qualifiers': { 46 | '': [ 47 | , # 每个qv都是像'value'一样的字典,包括'type', 'value'和'int' 48 | ] 49 | } 50 | } 51 | ] 52 | } 53 | } 54 | } 55 | 56 | .. image:: knowledge_element.jpg 57 | :width: 600 58 | :alt: Alternative text 59 | 60 | 例如,对于上图中的知识库,知识库为: 61 | 62 | :: 63 | 64 | example_kb = { 65 | 'concepts': { 66 | 'Q13393265': { 67 | 'name': 'basketball team', 68 | 'subclassOf': ['Q12973014'] 69 | }, 70 | 'Q12973014': { 71 | 'name': 'sports team', 72 | 'subclassOf': [] 73 | }, 74 | 'Q3665646': { 75 | 'name': 'basketball player', 76 | 'subclassOf': ['Q2066131'] 77 | }, 78 | 'Q2066131': { 79 | 'name': 'athlete', 80 | 'subclassOf': [] 81 | } 82 | }, 83 | 'entities': { 84 | 'Q36159': { 85 | 'name': 'LeBron James', 86 | 'instanceOf': ['Q3665646'], 87 | 'attributes': [ 88 | { 89 | 'key': 'height', 90 | 'value': { 91 | 'type': 'quantity', 92 | 'value': 206, 93 | 'unit': 'centimetre' 94 | }, 95 | 'qualifiers': {} 96 | }, 97 | { 98 | 'key': 'work period (start)', 99 | 'value': { 100 | 'type': 'year', 101 | 'value': 2003 102 | }, 103 | 'qualifiers': {} 104 | }, 105 | { 106 | 'key': 'sex or gender', 107 | 'value': { 108 | 'type': 'string', 109 | 'value': 'male' 110 | }, 111 | 'qualifiers': {} 112 | }, 113 | { 114 | 'key': 'date of birth', 115 | 'value': { 116 | 'type': 'date', 117 | 'value': '1984-12-30' 118 | }, 119 | 'qualifiers': {} 120 | } 121 | ], 122 | 'relations': [ 123 | { 124 | 'relation': 'place of birth', 125 | 'direction': 'forward', 126 | 'object': 'Q163132', 127 | 'qualifiers': {} 128 | }, 129 | { 130 | 'relation': 'drafted by', 131 | 'direction': 'forward', 132 | 'object': 'Q162990', 133 | 'qualifiers': { 134 | 'point in time': [ 135 | { 136 | 'type': 'date', 137 | 'value': '2003-06-26' 138 | } 139 | ] 140 | } 141 | }, 142 | { 143 | 'relation': 'child', 144 | 'direction': 'forward', 145 | 'object': 'Q22302425', 146 | 'qualifiers': {} 147 | 148 | }, 149 | { 150 | 'relation': 'member of sports team', 151 | 'direction': 'forward', 152 | 'object': 'Q162990', 153 | 'qualifiers': { 154 | 'position played on team/speciality': [ 155 | { 156 | 'type': 'string', 157 | 'value': 'small forward' 158 | } 159 | ], 160 | 'sport number': [ 161 | { 162 | 'type': 'quantity', 163 | 'value': 23, 164 | 'unit': '1' 165 | } 166 | ] 167 | } 168 | } 169 | ] 170 | }, 171 | 'Q163132': { 172 | 'name': 'Akron', 173 | 'instanceOf': [], 174 | 'attributes': [ 175 | { 176 | 'key': 'population', 177 | 'value': { 178 | 'type': 'quantity', 179 | 'value': 199110, 180 | 'unit': '1' 181 | }, 182 | 'qualifiers': { 183 | 'point in time': [ 184 | { 185 | 'type': 'year', 186 | 'value': 2010 187 | } 188 | ] 189 | } 190 | } 191 | ], 192 | 'relations': [] 193 | }, 194 | 'Q162990': { 195 | 'name': 'Cleveland Cavaliers', 196 | 'instanceOf': ['Q13393265'], 197 | 'attributes': [ 198 | { 199 | 'key': 'inception', 200 | 'value': { 201 | 'type': 'year', 202 | 'value': 1970 203 | }, 204 | 'qualifiers': {} 205 | } 206 | ], 207 | 'relations': [] 208 | }, 209 | 'Q22302425': { 210 | 'name': 'LeBron James Jr.', 211 | 'instanceOf': ['Q3665646'], 212 | 'attributes': [ 213 | { 214 | 'key': 'height', 215 | 'value': { 216 | 'type': 'quantity', 217 | 'value': 188, 218 | 'unit': 'centimetre' 219 | }, 220 | 'qualifiers': {} 221 | }, 222 | { 223 | 'key': 'sex or gender', 224 | 'value': { 225 | 'type': 'string', 226 | 'value': 'male' 227 | }, 228 | 'qualifiers': {} 229 | }, 230 | { 231 | 'key': 'date of birth', 232 | 'value': { 233 | 'type': 'date', 234 | 'value': '2004-10-06' 235 | }, 236 | 'qualifiers': {} 237 | } 238 | ], 239 | 'relations': [ 240 | { 241 | 'relation': 'father', 242 | 'direction': 'forward', 243 | 'object': 'Q36159', 244 | 'qualifiers': {} 245 | } 246 | ] 247 | 248 | } 249 | } 250 | 251 | } 252 | 253 | 254 | KoPL编程问答 255 | ---------------------------- 256 | 257 | KoPL的实现基于python,此处演示一个示例。更多API请参考API文档 258 | :doc:`7_kopl`,关于KoPL基本函数的介绍可以参考 259 | :doc:`2_function`。 260 | 261 | :: 262 | 263 | from kopl.kopl import KoPLEngine 264 | from kopl.test.test_example import example_kb 265 | 266 | engine = KoPLEngine(example_kb) 267 | 268 | ans = engine.SelectBetween( 269 | engine.Find('LeBron James Jr.'), 270 | engine.Relate( 271 | engine.Find('LeBron James Jr.'), 272 | 'father', 273 | 'forward' 274 | ), 275 | 'height', 276 | 'greater' 277 | ) 278 | 279 | print(ans) 280 | 281 | 在这个示例里,我们查询LeBron James Jr.和他的父亲谁更高,KoPL程序给出了正确的答案: LeBron James! 282 | 283 | 284 | 更多KoPL样例请参考 285 | :doc:`更多KoPL样例 <5_example>`。 286 | 287 | -------------------------------------------------------------------------------- /doc/source/_build/html/_sources/6_service.rst.txt: -------------------------------------------------------------------------------- 1 | 查询服务 2 | ============================================================================ 3 | 4 | 您可以准备自己的知识库,搭建自己的KoPL引擎来实现复杂推理问答,也可以使用我们为您提供的 `查询服务 `_ ,快速开启KoPL之旅~ 5 | 6 | 我们的查询引擎基于 `Wikidata15k `_ , 查询示例可以参考 7 | :doc:`更多KoPL样例 <5_example>`。 -------------------------------------------------------------------------------- /doc/source/_build/html/_sources/7_kopl.rst.txt: -------------------------------------------------------------------------------- 1 | KoPL引擎 2 | =========== 3 | 4 | .. automodule:: kopl.kopl 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /doc/source/_build/html/_sources/doc_1_knowledge.rst.txt: -------------------------------------------------------------------------------- 1 | ====================== 2 | KoPL面向的知识元素 3 | ====================== 4 | 5 | .. image:: knowledge_element.jpg 6 | :width: 600 7 | :alt: Alternative text 8 | 9 | 使用KoPL的前提是要有一个合适的目标知识库,该知识库中应该含有如下元素: 10 | 11 | - 实体(Entity) 12 | - 概念(Concept) 13 | - 谓语(Predicate) 14 | - 属性(Attribute) 15 | - 关系型知识(Relational Knowledge) 16 | - 属性型知识(LiteralKnowledge) 17 | - 修饰型知识(Qualifier Knowledge) 18 | 19 | 实体 20 | ----------------- 21 | 22 | .. glossary:: 23 | 24 | 知识库中最基本的元素,用来表示一个独一无二的事物。 25 | 26 | .. admonition:: 例子 27 | 28 | 勒布朗·詹姆斯(Lebron James)和克利夫兰骑士队(Cleveland Cavaliers)都是实体。 29 | 30 | 概念 31 | ----------------- 32 | 33 | .. glossary:: 34 | 35 | 表示一个实体集合。 36 | 37 | .. admonition:: 例子 38 | 39 | 篮球队(Basketball Team)便是一个概念。 40 | 41 | 谓语 42 | ----------------- 43 | 44 | .. glossary:: 45 | 46 | 表示两个实体之间的关系。特殊地,实体通过 *instance of* 关系链接到相应的概念上,概念之间通过 *subclass of* 关系来组织成层次结构。 47 | 48 | .. admonition:: 例子 49 | 50 | 父亲(*father*)和出生地(*place of birth*)都是关系。 51 | 52 | 属性 53 | ----------------- 54 | 55 | .. glossary:: 56 | 57 | 表示实体的属性信息。又由属性键和属性值两部分组成,属性值有字符串、数字、日期和年份4种类型。其中数值类型的属性值又包含单位,如“206厘米”中的“厘米”。 58 | 59 | .. admonition:: 例子 60 | 61 | 身高(height)是一个属性,206厘米是对应的属性值。 62 | 63 | 关系型知识 64 | ----------------- 65 | 66 | .. glossary:: 67 | 68 | 用于表示两个实体间关系的三元组, 由(实体,谓语,实体)组成。 69 | 70 | .. admonition:: 例子 71 | 72 | (勒布朗·詹姆斯,出生地,阿克伦)是一个关系型知识。 73 | 74 | 属性型知识 75 | ----------------- 76 | 77 | .. glossary:: 78 | 79 | 用于表示一个实体属性信息的三元组,由(实体,属性键,属性值)组成。 80 | 81 | .. admonition:: 例子 82 | 83 | (勒布朗·詹姆斯,身高,206厘米)是一个属性型知识。 84 | 85 | 修饰型知识 86 | ----------------- 87 | 88 | .. glossary:: 89 | 90 | 用于对一个关系型或属性型的三元组进行进一步的修饰,包含一个修饰键和一个修饰值。由(三元组,修饰键,修饰值)组成。 91 | 92 | .. admonition:: 例子 93 | 94 | ((勒布朗·詹姆斯,被选球队,克利夫兰骑士队),选择时间,2003年)是一个修饰型知识。 -------------------------------------------------------------------------------- /doc/source/_build/html/_sources/doc_3_engine.rst.txt: -------------------------------------------------------------------------------- 1 | KoPL 引擎 2 | =========== -------------------------------------------------------------------------------- /doc/source/_build/html/_sources/doc_4_example.rst.txt: -------------------------------------------------------------------------------- 1 | 使用示例 2 | =========== -------------------------------------------------------------------------------- /doc/source/_build/html/_sources/exam_1_input.rst.txt: -------------------------------------------------------------------------------- 1 | 用户输入 2 | =========== -------------------------------------------------------------------------------- /doc/source/_build/html/_sources/exam_2_schema.rst.txt: -------------------------------------------------------------------------------- 1 | schema 链接 2 | =========== -------------------------------------------------------------------------------- /doc/source/_build/html/_sources/example.rst.txt: -------------------------------------------------------------------------------- 1 | 2 | 3 | 知识库下载 4 | ===================================================================================================================================================================================== 5 | 我们从Wikidata中抽取了一个高质量的稠密子集 `Wikidata15k `_,包含794个概念,16,960个实体,363个关系,846个属性。以下的样例都基于这个知识库。 6 | 7 | 8 | 9 | 简单问答 10 | ==================================================================================================================================================== 11 | 12 | 查询属性 13 | ---------------------------------------------------------------- 14 | .. glossary:: 15 | 16 | 查询例句:When did the 1985 Major League Baseball season take place? 17 | 1985年美国职业棒球大联盟赛季是什么时候开始的? 18 | 查询结果:1985 19 | 20 | :: 21 | 22 | engine.QueryAttr( 23 | entities = engine.Find("1985 Major League Baseball season"), 24 | key = "point in time" 25 | ) 26 | 27 | 查询在修饰符限定下的属性 28 | ---------------------------------------------------------------- 29 | .. glossary:: 30 | 31 | 查询例句:Of New Jersey cities with under 350000 in population, which is biggest in terms of area? 32 | 在人口不到35万的新泽西州城市中,哪一个城市面积最大? 33 | 查询结果:1998-06-25 34 | 35 | :: 36 | 37 | engine.QueryAttrUnderCondition( 38 | entities = engine.Find("Oscar and Lucinda"), 39 | key = "publication date", 40 | qkey = "place of publication", 41 | qvalue = "Germany" 42 | ) 43 | 44 | 查询关系 45 | ---------------------------------------------------------------- 46 | .. glossary:: 47 | 48 | 查询例句:When did Will & Grace have 8 seasons? 49 | Will & Grace什么时候有了第8季? 50 | 查询结果:2006-05-18 51 | 52 | :: 53 | 54 | engine.QueryAttrQualifier( 55 | entities = engine.Find("Will & Grace"), 56 | key = "number of seasons", 57 | value = "8", 58 | qkey = "point in time" 59 | ) 60 | 61 | 查询属性的修饰值 62 | ---------------------------------------------------------------- 63 | .. glossary:: 64 | 65 | 查询例句:How is Viggo Mortensen releated to the 10th Screen Actors Guild Awards? 66 | Viggo Mortensen是如何获得第十届银幕演员协会奖的? 67 | 查询结果:award received 68 | 69 | :: 70 | 71 | engine.QueryRelation( 72 | s_entities = engine.Find("Viggo Mortensen"), 73 | t_entities = engine.Find("10th Screen Actors Guild Awards") 74 | ) 75 | 76 | 查询关系的修饰值 77 | ---------------------------------------------------------------- 78 | .. glossary:: 79 | 80 | 查询例句:When did Mitchell Hurwitz end his education at Georgetown University? 81 | Mitchell Hurwitz什么时候结束了在乔治敦大学的学业? 82 | 查询结果:1985 83 | 84 | :: 85 | 86 | engine.QueryRelationQualifier( 87 | s_entities = engine.Find("Mitchell Hurwitz"), 88 | t_entities = engine.Find("Georgetown University"), 89 | predicate = "educated at", 90 | qkey = "end time" 91 | ) 92 | 93 | 复杂问答 94 | ==================================================================================================================================================== 95 | 多跳查询 96 | ---------------------------------------------------------------- 97 | .. glossary:: 98 | 99 | 查询例句:How many industry computer languages are related to UNIX? 100 | 有多少种工业计算机语言与UNIX相关?? 101 | 查询结果:22 102 | 103 | :: 104 | 105 | engine.Count( 106 | engine.FilterConcept( 107 | engine.Relate( 108 | engine.FilterConcept( 109 | engine.Relate( 110 | engine.Find("Unix"), 111 | "relative", 112 | "backward" 113 | ), 114 | "industry" 115 | ), 116 | "language of work or name", 117 | "forward" 118 | ), 119 | "programming language" 120 | ) 121 | ) 122 | 123 | .. glossary:: 124 | 125 | 查询例句:Who is known for the new wave of European origin? 126 | 谁因欧洲起源的新浪潮而闻名? 127 | 查询结果:Gary Numan 128 | 129 | :: 130 | 131 | engine.QueryName( 132 | engine.FilterConcept( 133 | engine.Relate( 134 | engine.FilterConcept( 135 | engine.Relate( 136 | engine.Find("Europe"), 137 | "country of origin", 138 | "backward" 139 | ), 140 | "new wave" 141 | ), 142 | "famous people", 143 | "forward" 144 | ), 145 | "human" 146 | ) 147 | ) 148 | 149 | 比较 150 | ---------------------------------------------------------------- 151 | .. glossary:: 152 | 153 | 查询例句:Which show produced by Dreamworks is the longest? 154 | 梦工厂制作的哪个节目最长? 155 | 查询结果:Into the West 156 | 157 | :: 158 | 159 | engine.SelectAmong( 160 | engine.FilterConcept( 161 | engine.Relate( 162 | engine.Find("DreamWorks"), 163 | "production company", 164 | "backward" 165 | ), 166 | "miniseries" 167 | ), 168 | "duration", 169 | "largest" 170 | ) 171 | 172 | .. glossary:: 173 | 174 | 查询例句:Who is taller, Kobe Bryant or LeBron James? 175 | 谁更高,Kobe Bryant 还是 LeBron James? 176 | 查询结果:LeBron James 177 | 178 | :: 179 | 180 | engine.SelectBetween( 181 | engine.Find("Kobe Bryant"), 182 | engine.Find("LeBron James"), 183 | "height", 184 | "greater" 185 | ) 186 | 187 | 逻辑操作 188 | ---------------------------------------------------------------- 189 | .. glossary:: 190 | 191 | 查询例句:What feature film was nominated for an Academy Award for Best Supporting Actor and an Academy Award for Best Actor? 192 | 哪部故事片获得奥斯卡最佳男配角奖和最佳男主角奖提名? 193 | 查询结果:Fiddler on the Roof, Pirates of the Caribbean: The Curse of the Black Pearl, The Straight Story 194 | 195 | :: 196 | 197 | engine.QueryName( 198 | engine.And( 199 | engine.FilterConcept( 200 | engine.Relate( 201 | engine.Find("Academy Award for Best Actor"), 202 | "nominated for", 203 | "backward" 204 | ), 205 | "feature film" 206 | ), 207 | engine.FilterConcept( 208 | engine.Relate( 209 | engine.Find("Academy Award for Best Actor"), 210 | "nominated for", 211 | "backward" 212 | ), 213 | "feature film" 214 | ) 215 | ) 216 | ) 217 | 218 | .. glossary:: 219 | 220 | 查询例句:How many symptoms indicate lung cancer or have obesity as a risk factor? 221 | 有多少症状表明肺癌或肥胖是一个危险因素? 222 | 查询结果:4 223 | 224 | :: 225 | 226 | engine.Count( 227 | engine.Or( 228 | engine.FilterConcept( 229 | engine.Relate( 230 | engine.Find("lung cancer"), 231 | "symptoms", 232 | "forward" 233 | ), 234 | "symptom" 235 | ), 236 | engine.FilterConcept( 237 | engine.Relate( 238 | engine.Find("obesity"), 239 | "risk factor", 240 | "forward" 241 | ), 242 | "symptom" 243 | ) 244 | ) 245 | ) 246 | 247 | 事实验证 248 | ---------------------------------------------------------------- 249 | .. glossary:: 250 | 251 | 查询例句:Are there less than 30000 households on the date 2011-01-01 in the big city that is an administrative division of North Brabant? 252 | 在2011年1月1日,北布拉班特行政区的大城市的住户是否少于30000户? 253 | 查询结果:yes 254 | 255 | :: 256 | 257 | engine.QueryName( 258 | engine.QFilterStr( 259 | engine.Relate( 260 | engine.Find("Academy Award for Best Costume Design"), 261 | "winner", 262 | "forward" 263 | ), 264 | "for work", 265 | "Topsy-Turvy" 266 | ) 267 | ) 268 | 269 | .. glossary:: 270 | 271 | 查询例句:Did the television series titled All in the Family start on 1971-01-12? 272 | 这部名为《All in the Family》的电视连续剧是从1971年1月12日开始的吗? 273 | 查询结果:yes 274 | 275 | :: 276 | 277 | engine.VerifyDate( 278 | engine.QueryAttr( 279 | engine.FilterConcept( 280 | engine.FilterStr( 281 | engine.FindAll(), 282 | "title", 283 | "All in the Family" 284 | ), 285 | "television series" 286 | ), 287 | "start time" 288 | ), 289 | "1971-01-12", 290 | "=" 291 | ) 292 | -------------------------------------------------------------------------------- /doc/source/_build/html/_sources/glossary.rst.txt: -------------------------------------------------------------------------------- 1 | ====================== 2 | 术语 3 | ====================== -------------------------------------------------------------------------------- /doc/source/_build/html/_sources/helloworld.rst.txt: -------------------------------------------------------------------------------- 1 | 第一个KoPL程序 2 | ============ 3 | 4 | 5 | 准备知识库 6 | ----------------- 7 | 8 | 目前,我们支持JSON格式的知识库,其形式为: 9 | 10 | :: 11 | 12 | { 13 | # 概念 14 | 'concepts': { 15 | 'id': { 16 | 'name': '', 17 | 'subclassOf': [''], 18 | } 19 | }, 20 | # 实体,确保与概念是不相交的 21 | 'entities': { 22 | 'id': { 23 | 'name': '', 24 | 'instanceOf': [''], 25 | 'attributes': [ 26 | { 27 | 'key': '', 28 | 'value': { 29 | 'type': 'string'/'quantity'/'date'/'year' 30 | 'value': # quantity类型为float或int, year类型为int, date类型为'yyyy/mm/dd' 31 | 'unit': # 针对quantity类型,为str, 如'height'的unit可以是'centimetre', ‘population’的unit是‘1’ 32 | }, 33 | 'qualifiers': { 34 | '': [ 35 | , # 每个qv都是像'value'一样的字典,包括'type', 'value'和'int' 36 | ] 37 | } 38 | } 39 | ] 40 | 'relations': [ 41 | { 42 | 'relation': '', 43 | 'direction': 'forward' or 'backward', 44 | 'object': '', 45 | 'qualifiers': { 46 | '': [ 47 | , # 每个qv都是像'value'一样的字典,包括'type', 'value'和'int' 48 | ] 49 | } 50 | } 51 | ] 52 | } 53 | } 54 | } 55 | 56 | .. image:: knowledge_element.jpg 57 | :width: 600 58 | :alt: Alternative text 59 | 60 | 例如,对于上图中的知识库,知识库为: 61 | 62 | :: 63 | 64 | example_kb = { 65 | 'concepts': { 66 | 'Q13393265': { 67 | 'name': 'basketball team', 68 | 'subclassOf': ['Q12973014'] 69 | }, 70 | 'Q12973014': { 71 | 'name': 'sports team', 72 | 'subclassOf': [] 73 | }, 74 | 'Q3665646': { 75 | 'name': 'basketball player', 76 | 'subclassOf': ['Q2066131'] 77 | }, 78 | 'Q2066131': { 79 | 'name': 'athlete', 80 | 'subclassOf': [] 81 | } 82 | }, 83 | 'entities': { 84 | 'Q36159': { 85 | 'name': 'LeBron James', 86 | 'instanceOf': ['Q3665646'], 87 | 'attributes': [ 88 | { 89 | 'key': 'height', 90 | 'value': { 91 | 'type': 'quantity', 92 | 'value': 206, 93 | 'unit': 'centimetre' 94 | }, 95 | 'qualifiers': {} 96 | }, 97 | { 98 | 'key': 'work period (start)', 99 | 'value': { 100 | 'type': 'year', 101 | 'value': 2003 102 | }, 103 | 'qualifiers': {} 104 | }, 105 | { 106 | 'key': 'sex or gender', 107 | 'value': { 108 | 'type': 'string', 109 | 'value': 'male' 110 | }, 111 | 'qualifiers': {} 112 | }, 113 | { 114 | 'key': 'date of birth', 115 | 'value': { 116 | 'type': 'date', 117 | 'value': '1984-12-30' 118 | }, 119 | 'qualifiers': {} 120 | } 121 | ], 122 | 'relations': [ 123 | { 124 | 'relation': 'place of birth', 125 | 'direction': 'forward', 126 | 'object': 'Q163132', 127 | 'qualifiers': {} 128 | }, 129 | { 130 | 'relation': 'drafted by', 131 | 'direction': 'forward', 132 | 'object': 'Q162990', 133 | 'qualifiers': { 134 | 'point in time': [ 135 | { 136 | 'type': 'date', 137 | 'value': '2003-06-26' 138 | } 139 | ] 140 | } 141 | }, 142 | { 143 | 'relation': 'child', 144 | 'direction': 'forward', 145 | 'object': 'Q22302425', 146 | 'qualifiers': {} 147 | 148 | }, 149 | { 150 | 'relation': 'member of sports team', 151 | 'direction': 'forward', 152 | 'object': 'Q162990', 153 | 'qualifiers': { 154 | 'position played on team/speciality': [ 155 | { 156 | 'type': 'string', 157 | 'value': 'small forward' 158 | } 159 | ], 160 | 'sport number': [ 161 | { 162 | 'type': 'quantity', 163 | 'value': 23, 164 | 'unit': '1' 165 | } 166 | ] 167 | } 168 | } 169 | ] 170 | }, 171 | 'Q163132': { 172 | 'name': 'Akron', 173 | 'instanceOf': [], 174 | 'attributes': [ 175 | { 176 | 'key': 'population', 177 | 'value': { 178 | 'type': 'quantity', 179 | 'value': 199110, 180 | 'unit': '1' 181 | }, 182 | 'qualifiers': { 183 | 'point in time': [ 184 | { 185 | 'type': 'year', 186 | 'value': 2010 187 | } 188 | ] 189 | } 190 | } 191 | ], 192 | 'relations': [] 193 | }, 194 | 'Q162990': { 195 | 'name': 'Cleveland Cavaliers', 196 | 'instanceOf': ['Q13393265'], 197 | 'attributes': [ 198 | { 199 | 'key': 'inception', 200 | 'value': { 201 | 'type': 'year', 202 | 'value': 1970 203 | }, 204 | 'qualifiers': {} 205 | } 206 | ], 207 | 'relations': [] 208 | }, 209 | 'Q22302425': { 210 | 'name': 'LeBron James Jr.', 211 | 'instanceOf': ['Q3665646'], 212 | 'attributes': [ 213 | { 214 | 'key': 'height', 215 | 'value': { 216 | 'type': 'quantity', 217 | 'value': 188, 218 | 'unit': 'centimetre' 219 | }, 220 | 'qualifiers': {} 221 | }, 222 | { 223 | 'key': 'sex or gender', 224 | 'value': { 225 | 'type': 'string', 226 | 'value': 'male' 227 | }, 228 | 'qualifiers': {} 229 | }, 230 | { 231 | 'key': 'date of birth', 232 | 'value': { 233 | 'type': 'date', 234 | 'value': '2004-10-06' 235 | }, 236 | 'qualifiers': {} 237 | } 238 | ], 239 | 'relations': [ 240 | { 241 | 'relation': 'father', 242 | 'direction': 'forward', 243 | 'object': 'Q36159', 244 | 'qualifiers': {} 245 | } 246 | ] 247 | 248 | } 249 | } 250 | 251 | } 252 | 253 | 254 | KoPL编程问答 255 | ---------------------------- 256 | 257 | KoPL的实现基于python,此处演示一个示例。更多API请参考API文档 258 | :doc:`kopl`,关于KoPL元函数的介绍可以参考 259 | :doc:`function`。 260 | 261 | :: 262 | 263 | from kopl import kopl 264 | from kopl import util 265 | 266 | engine = kopl.KoPLEngine(example_kb) # 需要先把上面的example_kb复制在代码里 267 | 268 | ans = engine.SelectBetween( 269 | engine.Find('LeBron James Jr.'), 270 | engine.Relate( 271 | engine.Find('LeBron James Jr.'), 272 | relation = 'father', 273 | direction = 'forward' 274 | ), 275 | key = 'height', 276 | op = 'greater' 277 | ) 278 | 279 | print(ans) 280 | 281 | 在这个示例里,我们查询LeBron James Jr.和他的父亲谁更高,KoPL程序给出了正确的答案: LeBron James! 282 | 283 | 284 | 更多KoPL样例请参考 285 | :doc:`example` 286 | 287 | -------------------------------------------------------------------------------- /doc/source/_build/html/_sources/index.rst.txt: -------------------------------------------------------------------------------- 1 | .. KoPL documentation master file, created by 2 | sphinx-quickstart on Mon Oct 4 11:12:27 2021. 3 | You can adapt this file completely to your liking, but it should at least 4 | contain the root `toctree` directive. 5 | 6 | KoPL-面向知识的复杂问题推理编程语言 7 | ================================ 8 | .. toctree:: 9 | :maxdepth: 1 10 | :caption: KoPL入门 11 | 12 | 0_intro 13 | 1_knowledge 14 | 2_function 15 | 16 | .. toctree:: 17 | :maxdepth: 1 18 | :caption: 快速开始 19 | 20 | 3_install 21 | 4_helloworld 22 | 23 | .. toctree:: 24 | :maxdepth: 1 25 | :caption: 更多KoPL样例 26 | 27 | 5_example 28 | 6_service 29 | 30 | .. toctree:: 31 | :maxdepth: 1 32 | :caption: API文档 33 | 34 | 7_kopl 35 | 36 | 37 | Indices and tables 38 | ================== 39 | 40 | * :ref:`genindex` 41 | * :ref:`modindex` 42 | * :ref:`search` 43 | -------------------------------------------------------------------------------- /doc/source/_build/html/_sources/install.rst.txt: -------------------------------------------------------------------------------- 1 | 安装 2 | ============ 3 | 4 | KoPL支持Linux (e.g., Ubuntu/CentOS),macOS,Windows。 5 | 6 | 其中Linux和macOS的依赖为: 7 | 8 | :: 9 | 10 | python >= 3.6 11 | 12 | tqdm >= 4.62 13 | 14 | Windows对环境的要求为: 15 | 16 | :: 17 | 18 | Python >= 3.6 19 | 20 | tqdm >= 4.62 21 | 22 | x86_64处理器 23 | 24 | Windows10及以上 25 | 26 | 27 | KoPL提供pip安装, 下面将展示Ubuntu的安装命令: 28 | 29 | :: 30 | 31 | $ sudo apt install python3.7-dev 32 | 33 | $ python3.7 -m pip install KoPL 34 | 35 | 运行下面的代码 36 | 37 | :: 38 | 39 | import kopl 40 | from kopl.test.test_example import * 41 | run_test() 42 | 43 | 如果测试运行通过,恭喜您已经安装成功。 44 | -------------------------------------------------------------------------------- /doc/source/_build/html/_sources/intro.rst.txt: -------------------------------------------------------------------------------- 1 | 面向复杂推理问答的程序表示——KoPL 2 | ================================================================ 3 | 4 | KoPL是一个为复杂推理问答而设计的编程语言。我们可以将自然语言问题表示为由元函数组合而成的KoPL程序,程序运行的结果就是问题的答案。目前,KoPL的27个元函数覆盖对多种知识元素(如概念、实体、关系、属性、修饰符等)的操作,并支持多种问题类型(如计数、事实验证、比较等)的查询。KoPL提供透明的复杂问题推理过程,易于理解和使用。 5 | 6 | 设计理念 7 | ================================================================ 8 | - 显式、透明的推理过程 9 | - 易于理解,便于人机交互 10 | - 面向知识库、文本等不同形式的知识,可扩展性强 11 | -------------------------------------------------------------------------------- /doc/source/_build/html/_sources/knowledge.rst.txt: -------------------------------------------------------------------------------- 1 | ====================== 2 | KoPL面向的知识元素 3 | ====================== 4 | 5 | .. image:: knowledge_element.jpg 6 | :width: 600 7 | :alt: Alternative text 8 | 9 | 使用KoPL的前提是要有一个合适的目标知识库,该知识库中应该含有如下元素: 10 | 11 | - 实体(Entity) 12 | - 概念(Concept) 13 | - 关系(Relation) 14 | - 属性(Attribute) 15 | - 关系型知识(Relational Knowledge) 16 | - 属性型知识(LiteralKnowledge) 17 | - 修饰型知识(Qualifier Knowledge) 18 | 19 | 实体 20 | ----------------- 21 | 22 | .. glossary:: 23 | 24 | 知识库中最基本的元素,用来表示一个独一无二的事物。 25 | 26 | .. admonition:: 例子 27 | 28 | 勒布朗·詹姆斯(Lebron James)和克利夫兰骑士队(Cleveland Cavaliers)都是实体。 29 | 30 | 概念 31 | ----------------- 32 | 33 | .. glossary:: 34 | 35 | 表示一个实体集合。 36 | 37 | .. admonition:: 例子 38 | 39 | 篮球队(Basketball Team)便是一个概念。 40 | 41 | 关系 42 | ----------------- 43 | 44 | .. glossary:: 45 | 46 | 表示两个实体之间的关系。特殊地,实体通过 *instance of* 关系链接到相应的概念上,概念之间通过 *subclass of* 关系来组织成层次结构。 47 | 48 | .. admonition:: 例子 49 | 50 | 父亲(*father*)和出生地(*place of birth*)都是关系。 51 | 52 | 属性 53 | ----------------- 54 | 55 | .. glossary:: 56 | 57 | 表示实体的属性信息。又由属性键和属性值两部分组成,属性值有字符串、数字、日期和年份4种类型。其中数值类型的属性值又包含单位,如“206厘米”中的“厘米”。 58 | 59 | .. admonition:: 例子 60 | 61 | 身高(height)是一个属性,206厘米是对应的属性值。 62 | 63 | 关系型知识 64 | ----------------- 65 | 66 | .. glossary:: 67 | 68 | 用于表示两个实体间关系的三元组, 由(实体,关系,实体)组成。 69 | 70 | .. admonition:: 例子 71 | 72 | (勒布朗·詹姆斯,出生地,阿克伦)是一个关系型知识。 73 | 74 | 属性型知识 75 | ----------------- 76 | 77 | .. glossary:: 78 | 79 | 用于表示一个实体属性信息的三元组,由(实体,属性键,属性值)组成。 80 | 81 | .. admonition:: 例子 82 | 83 | (勒布朗·詹姆斯,身高,206厘米)是一个属性型知识。 84 | 85 | 修饰型知识 86 | ----------------- 87 | 88 | .. glossary:: 89 | 90 | 用于对一个关系型或属性型的三元组进行进一步的修饰,包含一个修饰键和一个修饰值。由(三元组,修饰键,修饰值)组成。 91 | 92 | .. admonition:: 例子 93 | 94 | ((勒布朗·詹姆斯,被选球队,克利夫兰骑士队),选择时间,2003年)是一个修饰型知识。 -------------------------------------------------------------------------------- /doc/source/_build/html/_sources/kopl.rst.txt: -------------------------------------------------------------------------------- 1 | KoPL引擎 2 | =========== 3 | 4 | .. automodule:: kopl.kopl 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /doc/source/_build/html/_sources/quick_start.rst.txt: -------------------------------------------------------------------------------- 1 | 第一个KoPL程序 2 | ============ 3 | 4 | 5 | 准备知识库 6 | ----------------- 7 | 8 | 目前,我们支持JSON格式的知识库,其形式为: 9 | 10 | :: 11 | 12 | { 13 | # 概念 14 | 'concepts': { 15 | 'id': { 16 | 'name': '', 17 | 'subclassOf': [''], 18 | } 19 | }, 20 | # 实体,确保与概念是不相交的 21 | 'entities': { 22 | 'id': { 23 | 'name': '', 24 | 'instanceOf': [''], 25 | 'attributes': [ 26 | { 27 | 'key': '', 28 | 'value': { 29 | 'type': 'string'/'quantity'/'date'/'year' 30 | 'value': # quantity类型为float或int, year类型为int, date类型为'yyyy/mm/dd' 31 | 'unit': # 针对quantity类型,为str, 如'height'的unit可以是'centimetre', ‘population’的unit是‘1’ 32 | }, 33 | 'qualifiers': { 34 | '': [ 35 | , # 每个qv都是像'value'一样的字典,包括'type', 'value'和'int' 36 | ] 37 | } 38 | } 39 | ] 40 | 'relations': [ 41 | { 42 | 'relation': '', 43 | 'direction': 'forward' or 'backward', 44 | 'object': '', 45 | 'qualifiers': { 46 | '': [ 47 | , # 每个qv都是像'value'一样的字典,包括'type', 'value'和'int' 48 | ] 49 | } 50 | } 51 | ] 52 | } 53 | } 54 | } 55 | 56 | .. image:: knowledge_element.jpg 57 | :width: 600 58 | :alt: Alternative text 59 | 60 | 例如,对于上图中的知识库,知识库为: 61 | 62 | :: 63 | 64 | example_kb = { 65 | 'concepts': { 66 | 'Q13393265': { 67 | 'name': 'basketball team', 68 | 'subclassOf': ['Q12973014'] 69 | }, 70 | 'Q12973014': { 71 | 'name': 'sports team', 72 | 'subclassOf': [] 73 | }, 74 | 'Q3665646': { 75 | 'name': 'basketball player', 76 | 'subclassOf': ['Q2066131'] 77 | }, 78 | 'Q2066131': { 79 | 'name': 'athlete', 80 | 'subclassOf': [] 81 | } 82 | }, 83 | 'entities': { 84 | 'Q36159': { 85 | 'name': 'LeBron James', 86 | 'instanceOf': ['Q3665646'], 87 | 'attributes': [ 88 | { 89 | 'key': 'height', 90 | 'value': { 91 | 'type': 'quantity', 92 | 'value': 206, 93 | 'unit': 'centimetre' 94 | }, 95 | 'qualifiers': {} 96 | }, 97 | { 98 | 'key': 'work period (start)', 99 | 'value': { 100 | 'type': 'year', 101 | 'value': 2003 102 | }, 103 | 'qualifiers': {} 104 | }, 105 | { 106 | 'key': 'sex or gender', 107 | 'value': { 108 | 'type': 'string', 109 | 'value': 'male' 110 | }, 111 | 'qualifiers': {} 112 | }, 113 | { 114 | 'key': 'date of birth', 115 | 'value': { 116 | 'type': 'date', 117 | 'value': '1984-12-30' 118 | }, 119 | 'qualifiers': {} 120 | } 121 | ], 122 | 'relations': [ 123 | { 124 | 'relation': 'place of birth', 125 | 'direction': 'forward', 126 | 'object': 'Q163132', 127 | 'qualifiers': {} 128 | }, 129 | { 130 | 'relation': 'drafted by', 131 | 'direction': 'forward', 132 | 'object': 'Q162990', 133 | 'qualifiers': { 134 | 'point in time': [ 135 | { 136 | 'type': 'date', 137 | 'value': '2003-06-26' 138 | } 139 | ] 140 | } 141 | }, 142 | { 143 | 'relation': 'child', 144 | 'direction': 'forward', 145 | 'object': 'Q22302425', 146 | 'qualifiers': {} 147 | 148 | }, 149 | { 150 | 'relation': 'member of sports team', 151 | 'direction': 'forward', 152 | 'object': 'Q162990', 153 | 'qualifiers': { 154 | 'position played on team/speciality': [ 155 | { 156 | 'type': 'string', 157 | 'value': 'small forward' 158 | } 159 | ], 160 | 'sport number': [ 161 | { 162 | 'type': 'quantity', 163 | 'value': 23, 164 | 'unit': '1' 165 | } 166 | ] 167 | } 168 | } 169 | ] 170 | }, 171 | 'Q163132': { 172 | 'name': 'Akron', 173 | 'instanceOf': [], 174 | 'attributes': [ 175 | { 176 | 'key': 'population', 177 | 'value': { 178 | 'type': 'quantity', 179 | 'value': 199110, 180 | 'unit': '1' 181 | }, 182 | 'qualifiers': { 183 | 'point in time': [ 184 | { 185 | 'type': 'year', 186 | 'value': 2010 187 | } 188 | ] 189 | } 190 | } 191 | ], 192 | 'relations': [] 193 | }, 194 | 'Q162990': { 195 | 'name': 'Cleveland Cavaliers', 196 | 'instanceOf': ['Q13393265'], 197 | 'attributes': [ 198 | { 199 | 'key': 'inception', 200 | 'value': { 201 | 'type': 'year', 202 | 'value': 1970 203 | }, 204 | 'qualifiers': {} 205 | } 206 | ], 207 | 'relations': [] 208 | }, 209 | 'Q22302425': { 210 | 'name': 'LeBron James Jr.', 211 | 'instanceOf': ['Q3665646'], 212 | 'attributes': [ 213 | { 214 | 'key': 'height', 215 | 'value': { 216 | 'type': 'quantity', 217 | 'value': 188, 218 | 'unit': 'centimetre' 219 | }, 220 | 'qualifiers': {} 221 | }, 222 | { 223 | 'key': 'sex or gender', 224 | 'value': { 225 | 'type': 'string', 226 | 'value': 'male' 227 | }, 228 | 'qualifiers': {} 229 | }, 230 | { 231 | 'key': 'date of birth', 232 | 'value': { 233 | 'type': 'date', 234 | 'value': '2004-10-06' 235 | }, 236 | 'qualifiers': {} 237 | } 238 | ], 239 | 'relations': [ 240 | { 241 | 'relation': 'father', 242 | 'direction': 'forward', 243 | 'object': 'Q36159', 244 | 'qualifiers': {} 245 | } 246 | ] 247 | 248 | } 249 | } 250 | 251 | } 252 | 253 | 254 | KoPL编程问答 255 | ---------------------------- 256 | 257 | KoPL的实现基于python,此处演示一个示例。更多API请参考API文档 258 | :doc:`kopl` 259 | 260 | :: 261 | 262 | from kopl import kopl 263 | from kopl import util 264 | 265 | engine = kopl.KoPLEngine(example_kb) # 需要先把上面的example_kb复制在代码里 266 | 267 | ans = engine.SelectBetween( 268 | engine.Find('LeBron James Jr.'), 269 | engine.Relate( 270 | engine.Find('LeBron James Jr.'), 271 | relation = 'father', 272 | direction = 'forward' 273 | ), 274 | key = 'height', 275 | op = 'greater' 276 | ) 277 | 278 | print(ans) 279 | 280 | 在这个示例里,我们查询LeBron James Jr.和他的父亲谁更高,KoPL程序给出了正确的答案: LeBron James! 281 | 282 | 283 | 更多KoPL样例请参考 284 | :doc:`example` 285 | 286 | -------------------------------------------------------------------------------- /doc/source/_build/html/_sources/service.rst.txt: -------------------------------------------------------------------------------- 1 | 查询服务 2 | ============================================================================ 3 | 4 | 您可以准备自己的知识库,搭建自己的KoPL引擎来实现复杂推理问答,也可以使用我们为您提供的查询服务,快速开启KoPL之旅~ 5 | 6 | -------------------------------------------------------------------------------- /doc/source/_build/html/_static/css/badge_only.css: -------------------------------------------------------------------------------- 1 | .fa:before{-webkit-font-smoothing:antialiased}.clearfix{*zoom:1}.clearfix:after,.clearfix:before{display:table;content:""}.clearfix:after{clear:both}@font-face{font-family:FontAwesome;font-style:normal;font-weight:400;src:url(fonts/fontawesome-webfont.eot?674f50d287a8c48dc19ba404d20fe713?#iefix) format("embedded-opentype"),url(fonts/fontawesome-webfont.woff2?af7ae505a9eed503f8b8e6982036873e) format("woff2"),url(fonts/fontawesome-webfont.woff?fee66e712a8a08eef5805a46892932ad) format("woff"),url(fonts/fontawesome-webfont.ttf?b06871f281fee6b241d60582ae9369b9) format("truetype"),url(fonts/fontawesome-webfont.svg?912ec66d7572ff821749319396470bde#FontAwesome) format("svg")}.fa:before{font-family:FontAwesome;font-style:normal;font-weight:400;line-height:1}.fa:before,a .fa{text-decoration:inherit}.fa:before,a .fa,li .fa{display:inline-block}li .fa-large:before{width:1.875em}ul.fas{list-style-type:none;margin-left:2em;text-indent:-.8em}ul.fas li .fa{width:.8em}ul.fas li .fa-large:before{vertical-align:baseline}.fa-book:before,.icon-book:before{content:"\f02d"}.fa-caret-down:before,.icon-caret-down:before{content:"\f0d7"}.fa-caret-up:before,.icon-caret-up:before{content:"\f0d8"}.fa-caret-left:before,.icon-caret-left:before{content:"\f0d9"}.fa-caret-right:before,.icon-caret-right:before{content:"\f0da"}.rst-versions{position:fixed;bottom:0;left:0;width:300px;color:#fcfcfc;background:#1f1d1d;font-family:Lato,proxima-nova,Helvetica Neue,Arial,sans-serif;z-index:400}.rst-versions a{color:#2980b9;text-decoration:none}.rst-versions .rst-badge-small{display:none}.rst-versions .rst-current-version{padding:12px;background-color:#272525;display:block;text-align:right;font-size:90%;cursor:pointer;color:#27ae60}.rst-versions .rst-current-version:after{clear:both;content:"";display:block}.rst-versions .rst-current-version .fa{color:#fcfcfc}.rst-versions .rst-current-version .fa-book,.rst-versions .rst-current-version .icon-book{float:left}.rst-versions .rst-current-version.rst-out-of-date{background-color:#e74c3c;color:#fff}.rst-versions .rst-current-version.rst-active-old-version{background-color:#f1c40f;color:#000}.rst-versions.shift-up{height:auto;max-height:100%;overflow-y:scroll}.rst-versions.shift-up .rst-other-versions{display:block}.rst-versions .rst-other-versions{font-size:90%;padding:12px;color:grey;display:none}.rst-versions .rst-other-versions hr{display:block;height:1px;border:0;margin:20px 0;padding:0;border-top:1px solid #413d3d}.rst-versions .rst-other-versions dd{display:inline-block;margin:0}.rst-versions .rst-other-versions dd a{display:inline-block;padding:6px;color:#fcfcfc}.rst-versions.rst-badge{width:auto;bottom:20px;right:20px;left:auto;border:none;max-width:300px;max-height:90%}.rst-versions.rst-badge .fa-book,.rst-versions.rst-badge .icon-book{float:none;line-height:30px}.rst-versions.rst-badge.shift-up .rst-current-version{text-align:right}.rst-versions.rst-badge.shift-up .rst-current-version .fa-book,.rst-versions.rst-badge.shift-up .rst-current-version .icon-book{float:left}.rst-versions.rst-badge>.rst-current-version{width:auto;height:30px;line-height:30px;padding:0 6px;display:block;text-align:center}@media screen and (max-width:768px){.rst-versions{width:85%;display:none}.rst-versions.shift{display:block}} -------------------------------------------------------------------------------- /doc/source/_build/html/_static/css/fonts/Roboto-Slab-Bold.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THU-KEG/KoPL/486c07bd83ea32268ff90fa6942cc9f7e1574ae5/doc/source/_build/html/_static/css/fonts/Roboto-Slab-Bold.woff -------------------------------------------------------------------------------- /doc/source/_build/html/_static/css/fonts/Roboto-Slab-Bold.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THU-KEG/KoPL/486c07bd83ea32268ff90fa6942cc9f7e1574ae5/doc/source/_build/html/_static/css/fonts/Roboto-Slab-Bold.woff2 -------------------------------------------------------------------------------- /doc/source/_build/html/_static/css/fonts/Roboto-Slab-Regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THU-KEG/KoPL/486c07bd83ea32268ff90fa6942cc9f7e1574ae5/doc/source/_build/html/_static/css/fonts/Roboto-Slab-Regular.woff -------------------------------------------------------------------------------- /doc/source/_build/html/_static/css/fonts/Roboto-Slab-Regular.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THU-KEG/KoPL/486c07bd83ea32268ff90fa6942cc9f7e1574ae5/doc/source/_build/html/_static/css/fonts/Roboto-Slab-Regular.woff2 -------------------------------------------------------------------------------- /doc/source/_build/html/_static/css/fonts/fontawesome-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THU-KEG/KoPL/486c07bd83ea32268ff90fa6942cc9f7e1574ae5/doc/source/_build/html/_static/css/fonts/fontawesome-webfont.eot -------------------------------------------------------------------------------- /doc/source/_build/html/_static/css/fonts/fontawesome-webfont.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THU-KEG/KoPL/486c07bd83ea32268ff90fa6942cc9f7e1574ae5/doc/source/_build/html/_static/css/fonts/fontawesome-webfont.ttf -------------------------------------------------------------------------------- /doc/source/_build/html/_static/css/fonts/fontawesome-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THU-KEG/KoPL/486c07bd83ea32268ff90fa6942cc9f7e1574ae5/doc/source/_build/html/_static/css/fonts/fontawesome-webfont.woff -------------------------------------------------------------------------------- /doc/source/_build/html/_static/css/fonts/fontawesome-webfont.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THU-KEG/KoPL/486c07bd83ea32268ff90fa6942cc9f7e1574ae5/doc/source/_build/html/_static/css/fonts/fontawesome-webfont.woff2 -------------------------------------------------------------------------------- /doc/source/_build/html/_static/css/fonts/lato-bold-italic.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THU-KEG/KoPL/486c07bd83ea32268ff90fa6942cc9f7e1574ae5/doc/source/_build/html/_static/css/fonts/lato-bold-italic.woff -------------------------------------------------------------------------------- /doc/source/_build/html/_static/css/fonts/lato-bold-italic.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THU-KEG/KoPL/486c07bd83ea32268ff90fa6942cc9f7e1574ae5/doc/source/_build/html/_static/css/fonts/lato-bold-italic.woff2 -------------------------------------------------------------------------------- /doc/source/_build/html/_static/css/fonts/lato-bold.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THU-KEG/KoPL/486c07bd83ea32268ff90fa6942cc9f7e1574ae5/doc/source/_build/html/_static/css/fonts/lato-bold.woff -------------------------------------------------------------------------------- /doc/source/_build/html/_static/css/fonts/lato-bold.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THU-KEG/KoPL/486c07bd83ea32268ff90fa6942cc9f7e1574ae5/doc/source/_build/html/_static/css/fonts/lato-bold.woff2 -------------------------------------------------------------------------------- /doc/source/_build/html/_static/css/fonts/lato-normal-italic.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THU-KEG/KoPL/486c07bd83ea32268ff90fa6942cc9f7e1574ae5/doc/source/_build/html/_static/css/fonts/lato-normal-italic.woff -------------------------------------------------------------------------------- /doc/source/_build/html/_static/css/fonts/lato-normal-italic.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THU-KEG/KoPL/486c07bd83ea32268ff90fa6942cc9f7e1574ae5/doc/source/_build/html/_static/css/fonts/lato-normal-italic.woff2 -------------------------------------------------------------------------------- /doc/source/_build/html/_static/css/fonts/lato-normal.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THU-KEG/KoPL/486c07bd83ea32268ff90fa6942cc9f7e1574ae5/doc/source/_build/html/_static/css/fonts/lato-normal.woff -------------------------------------------------------------------------------- /doc/source/_build/html/_static/css/fonts/lato-normal.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THU-KEG/KoPL/486c07bd83ea32268ff90fa6942cc9f7e1574ae5/doc/source/_build/html/_static/css/fonts/lato-normal.woff2 -------------------------------------------------------------------------------- /doc/source/_build/html/_static/documentation_options.js: -------------------------------------------------------------------------------- 1 | var DOCUMENTATION_OPTIONS = { 2 | URL_ROOT: document.getElementById("documentation_options").getAttribute('data-url_root'), 3 | VERSION: '1.0.0', 4 | LANGUAGE: 'None', 5 | COLLAPSE_INDEX: false, 6 | BUILDER: 'html', 7 | FILE_SUFFIX: '.html', 8 | LINK_SUFFIX: '.html', 9 | HAS_SOURCE: false, 10 | SOURCELINK_SUFFIX: '.txt', 11 | NAVIGATION_WITH_KEYS: false 12 | }; -------------------------------------------------------------------------------- /doc/source/_build/html/_static/file.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THU-KEG/KoPL/486c07bd83ea32268ff90fa6942cc9f7e1574ae5/doc/source/_build/html/_static/file.png -------------------------------------------------------------------------------- /doc/source/_build/html/_static/js/badge_only.js: -------------------------------------------------------------------------------- 1 | !function(e){var t={};function r(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)r.d(n,o,function(t){return e[t]}.bind(null,o));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=4)}({4:function(e,t,r){}}); -------------------------------------------------------------------------------- /doc/source/_build/html/_static/js/html5shiv-printshiv.min.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @preserve HTML5 Shiv 3.7.3-pre | @afarkas @jdalton @jon_neal @rem | MIT/GPL2 Licensed 3 | */ 4 | !function(a,b){function c(a,b){var c=a.createElement("p"),d=a.getElementsByTagName("head")[0]||a.documentElement;return c.innerHTML="x",d.insertBefore(c.lastChild,d.firstChild)}function d(){var a=y.elements;return"string"==typeof a?a.split(" "):a}function e(a,b){var c=y.elements;"string"!=typeof c&&(c=c.join(" ")),"string"!=typeof a&&(a=a.join(" ")),y.elements=c+" "+a,j(b)}function f(a){var b=x[a[v]];return b||(b={},w++,a[v]=w,x[w]=b),b}function g(a,c,d){if(c||(c=b),q)return c.createElement(a);d||(d=f(c));var e;return e=d.cache[a]?d.cache[a].cloneNode():u.test(a)?(d.cache[a]=d.createElem(a)).cloneNode():d.createElem(a),!e.canHaveChildren||t.test(a)||e.tagUrn?e:d.frag.appendChild(e)}function h(a,c){if(a||(a=b),q)return a.createDocumentFragment();c=c||f(a);for(var e=c.frag.cloneNode(),g=0,h=d(),i=h.length;i>g;g++)e.createElement(h[g]);return e}function i(a,b){b.cache||(b.cache={},b.createElem=a.createElement,b.createFrag=a.createDocumentFragment,b.frag=b.createFrag()),a.createElement=function(c){return y.shivMethods?g(c,a,b):b.createElem(c)},a.createDocumentFragment=Function("h,f","return function(){var n=f.cloneNode(),c=n.createElement;h.shivMethods&&("+d().join().replace(/[\w\-:]+/g,function(a){return b.createElem(a),b.frag.createElement(a),'c("'+a+'")'})+");return n}")(y,b.frag)}function j(a){a||(a=b);var d=f(a);return!y.shivCSS||p||d.hasCSS||(d.hasCSS=!!c(a,"article,aside,dialog,figcaption,figure,footer,header,hgroup,main,nav,section{display:block}mark{background:#FF0;color:#000}template{display:none}")),q||i(a,d),a}function k(a){for(var b,c=a.getElementsByTagName("*"),e=c.length,f=RegExp("^(?:"+d().join("|")+")$","i"),g=[];e--;)b=c[e],f.test(b.nodeName)&&g.push(b.applyElement(l(b)));return g}function l(a){for(var b,c=a.attributes,d=c.length,e=a.ownerDocument.createElement(A+":"+a.nodeName);d--;)b=c[d],b.specified&&e.setAttribute(b.nodeName,b.nodeValue);return e.style.cssText=a.style.cssText,e}function m(a){for(var b,c=a.split("{"),e=c.length,f=RegExp("(^|[\\s,>+~])("+d().join("|")+")(?=[[\\s,>+~#.:]|$)","gi"),g="$1"+A+"\\:$2";e--;)b=c[e]=c[e].split("}"),b[b.length-1]=b[b.length-1].replace(f,g),c[e]=b.join("}");return c.join("{")}function n(a){for(var b=a.length;b--;)a[b].removeNode()}function o(a){function b(){clearTimeout(g._removeSheetTimer),d&&d.removeNode(!0),d=null}var d,e,g=f(a),h=a.namespaces,i=a.parentWindow;return!B||a.printShived?a:("undefined"==typeof h[A]&&h.add(A),i.attachEvent("onbeforeprint",function(){b();for(var f,g,h,i=a.styleSheets,j=[],l=i.length,n=Array(l);l--;)n[l]=i[l];for(;h=n.pop();)if(!h.disabled&&z.test(h.media)){try{f=h.imports,g=f.length}catch(o){g=0}for(l=0;g>l;l++)n.push(f[l]);try{j.push(h.cssText)}catch(o){}}j=m(j.reverse().join("")),e=k(a),d=c(a,j)}),i.attachEvent("onafterprint",function(){n(e),clearTimeout(g._removeSheetTimer),g._removeSheetTimer=setTimeout(b,500)}),a.printShived=!0,a)}var p,q,r="3.7.3",s=a.html5||{},t=/^<|^(?:button|map|select|textarea|object|iframe|option|optgroup)$/i,u=/^(?:a|b|code|div|fieldset|h1|h2|h3|h4|h5|h6|i|label|li|ol|p|q|span|strong|style|table|tbody|td|th|tr|ul)$/i,v="_html5shiv",w=0,x={};!function(){try{var a=b.createElement("a");a.innerHTML="",p="hidden"in a,q=1==a.childNodes.length||function(){b.createElement("a");var a=b.createDocumentFragment();return"undefined"==typeof a.cloneNode||"undefined"==typeof a.createDocumentFragment||"undefined"==typeof a.createElement}()}catch(c){p=!0,q=!0}}();var y={elements:s.elements||"abbr article aside audio bdi canvas data datalist details dialog figcaption figure footer header hgroup main mark meter nav output picture progress section summary template time video",version:r,shivCSS:s.shivCSS!==!1,supportsUnknownElements:q,shivMethods:s.shivMethods!==!1,type:"default",shivDocument:j,createElement:g,createDocumentFragment:h,addElements:e};a.html5=y,j(b);var z=/^$|\b(?:all|print)\b/,A="html5shiv",B=!q&&function(){var c=b.documentElement;return!("undefined"==typeof b.namespaces||"undefined"==typeof b.parentWindow||"undefined"==typeof c.applyElement||"undefined"==typeof c.removeNode||"undefined"==typeof a.attachEvent)}();y.type+=" print",y.shivPrint=o,o(b),"object"==typeof module&&module.exports&&(module.exports=y)}("undefined"!=typeof window?window:this,document); -------------------------------------------------------------------------------- /doc/source/_build/html/_static/js/html5shiv.min.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @preserve HTML5 Shiv 3.7.3 | @afarkas @jdalton @jon_neal @rem | MIT/GPL2 Licensed 3 | */ 4 | !function(a,b){function c(a,b){var c=a.createElement("p"),d=a.getElementsByTagName("head")[0]||a.documentElement;return c.innerHTML="x",d.insertBefore(c.lastChild,d.firstChild)}function d(){var a=t.elements;return"string"==typeof a?a.split(" "):a}function e(a,b){var c=t.elements;"string"!=typeof c&&(c=c.join(" ")),"string"!=typeof a&&(a=a.join(" ")),t.elements=c+" "+a,j(b)}function f(a){var b=s[a[q]];return b||(b={},r++,a[q]=r,s[r]=b),b}function g(a,c,d){if(c||(c=b),l)return c.createElement(a);d||(d=f(c));var e;return e=d.cache[a]?d.cache[a].cloneNode():p.test(a)?(d.cache[a]=d.createElem(a)).cloneNode():d.createElem(a),!e.canHaveChildren||o.test(a)||e.tagUrn?e:d.frag.appendChild(e)}function h(a,c){if(a||(a=b),l)return a.createDocumentFragment();c=c||f(a);for(var e=c.frag.cloneNode(),g=0,h=d(),i=h.length;i>g;g++)e.createElement(h[g]);return e}function i(a,b){b.cache||(b.cache={},b.createElem=a.createElement,b.createFrag=a.createDocumentFragment,b.frag=b.createFrag()),a.createElement=function(c){return t.shivMethods?g(c,a,b):b.createElem(c)},a.createDocumentFragment=Function("h,f","return function(){var n=f.cloneNode(),c=n.createElement;h.shivMethods&&("+d().join().replace(/[\w\-:]+/g,function(a){return b.createElem(a),b.frag.createElement(a),'c("'+a+'")'})+");return n}")(t,b.frag)}function j(a){a||(a=b);var d=f(a);return!t.shivCSS||k||d.hasCSS||(d.hasCSS=!!c(a,"article,aside,dialog,figcaption,figure,footer,header,hgroup,main,nav,section{display:block}mark{background:#FF0;color:#000}template{display:none}")),l||i(a,d),a}var k,l,m="3.7.3-pre",n=a.html5||{},o=/^<|^(?:button|map|select|textarea|object|iframe|option|optgroup)$/i,p=/^(?:a|b|code|div|fieldset|h1|h2|h3|h4|h5|h6|i|label|li|ol|p|q|span|strong|style|table|tbody|td|th|tr|ul)$/i,q="_html5shiv",r=0,s={};!function(){try{var a=b.createElement("a");a.innerHTML="",k="hidden"in a,l=1==a.childNodes.length||function(){b.createElement("a");var a=b.createDocumentFragment();return"undefined"==typeof a.cloneNode||"undefined"==typeof a.createDocumentFragment||"undefined"==typeof a.createElement}()}catch(c){k=!0,l=!0}}();var t={elements:n.elements||"abbr article aside audio bdi canvas data datalist details dialog figcaption figure footer header hgroup main mark meter nav output picture progress section summary template time video",version:m,shivCSS:n.shivCSS!==!1,supportsUnknownElements:l,shivMethods:n.shivMethods!==!1,type:"default",shivDocument:j,createElement:g,createDocumentFragment:h,addElements:e};a.html5=t,j(b),"object"==typeof module&&module.exports&&(module.exports=t)}("undefined"!=typeof window?window:this,document); -------------------------------------------------------------------------------- /doc/source/_build/html/_static/js/theme.js: -------------------------------------------------------------------------------- 1 | !function(n){var e={};function t(i){if(e[i])return e[i].exports;var o=e[i]={i:i,l:!1,exports:{}};return n[i].call(o.exports,o,o.exports,t),o.l=!0,o.exports}t.m=n,t.c=e,t.d=function(n,e,i){t.o(n,e)||Object.defineProperty(n,e,{enumerable:!0,get:i})},t.r=function(n){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(n,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(n,"__esModule",{value:!0})},t.t=function(n,e){if(1&e&&(n=t(n)),8&e)return n;if(4&e&&"object"==typeof n&&n&&n.__esModule)return n;var i=Object.create(null);if(t.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:n}),2&e&&"string"!=typeof n)for(var o in n)t.d(i,o,function(e){return n[e]}.bind(null,o));return i},t.n=function(n){var e=n&&n.__esModule?function(){return n.default}:function(){return n};return t.d(e,"a",e),e},t.o=function(n,e){return Object.prototype.hasOwnProperty.call(n,e)},t.p="",t(t.s=0)}([function(n,e,t){t(1),n.exports=t(3)},function(n,e,t){(function(){var e="undefined"!=typeof window?window.jQuery:t(2);n.exports.ThemeNav={navBar:null,win:null,winScroll:!1,winResize:!1,linkScroll:!1,winPosition:0,winHeight:null,docHeight:null,isRunning:!1,enable:function(n){var t=this;void 0===n&&(n=!0),t.isRunning||(t.isRunning=!0,e((function(e){t.init(e),t.reset(),t.win.on("hashchange",t.reset),n&&t.win.on("scroll",(function(){t.linkScroll||t.winScroll||(t.winScroll=!0,requestAnimationFrame((function(){t.onScroll()})))})),t.win.on("resize",(function(){t.winResize||(t.winResize=!0,requestAnimationFrame((function(){t.onResize()})))})),t.onResize()})))},enableSticky:function(){this.enable(!0)},init:function(n){n(document);var e=this;this.navBar=n("div.wy-side-scroll:first"),this.win=n(window),n(document).on("click","[data-toggle='wy-nav-top']",(function(){n("[data-toggle='wy-nav-shift']").toggleClass("shift"),n("[data-toggle='rst-versions']").toggleClass("shift")})).on("click",".wy-menu-vertical .current ul li a",(function(){var t=n(this);n("[data-toggle='wy-nav-shift']").removeClass("shift"),n("[data-toggle='rst-versions']").toggleClass("shift"),e.toggleCurrent(t),e.hashChange()})).on("click","[data-toggle='rst-current-version']",(function(){n("[data-toggle='rst-versions']").toggleClass("shift-up")})),n("table.docutils:not(.field-list,.footnote,.citation)").wrap("
"),n("table.docutils.footnote").wrap("
"),n("table.docutils.citation").wrap("
"),n(".wy-menu-vertical ul").not(".simple").siblings("a").each((function(){var t=n(this);expand=n(''),expand.on("click",(function(n){return e.toggleCurrent(t),n.stopPropagation(),!1})),t.prepend(expand)}))},reset:function(){var n=encodeURI(window.location.hash)||"#";try{var e=$(".wy-menu-vertical"),t=e.find('[href="'+n+'"]');if(0===t.length){var i=$('.document [id="'+n.substring(1)+'"]').closest("div.section");0===(t=e.find('[href="#'+i.attr("id")+'"]')).length&&(t=e.find('[href="#"]'))}if(t.length>0){$(".wy-menu-vertical .current").removeClass("current").attr("aria-expanded","false"),t.addClass("current").attr("aria-expanded","true"),t.closest("li.toctree-l1").parent().addClass("current").attr("aria-expanded","true");for(let n=1;n<=10;n++)t.closest("li.toctree-l"+n).addClass("current").attr("aria-expanded","true");t[0].scrollIntoView()}}catch(n){console.log("Error expanding nav for anchor",n)}},onScroll:function(){this.winScroll=!1;var n=this.win.scrollTop(),e=n+this.winHeight,t=this.navBar.scrollTop()+(n-this.winPosition);n<0||e>this.docHeight||(this.navBar.scrollTop(t),this.winPosition=n)},onResize:function(){this.winResize=!1,this.winHeight=this.win.height(),this.docHeight=$(document).height()},hashChange:function(){this.linkScroll=!0,this.win.one("hashchange",(function(){this.linkScroll=!1}))},toggleCurrent:function(n){var e=n.closest("li");e.siblings("li.current").removeClass("current").attr("aria-expanded","false"),e.siblings().find("li.current").removeClass("current").attr("aria-expanded","false");var t=e.find("> ul li");t.length&&(t.removeClass("current").attr("aria-expanded","false"),e.toggleClass("current").attr("aria-expanded",(function(n,e){return"true"==e?"false":"true"})))}},"undefined"!=typeof window&&(window.SphinxRtdTheme={Navigation:n.exports.ThemeNav,StickyNav:n.exports.ThemeNav}),function(){for(var n=0,e=["ms","moz","webkit","o"],t=0;t 2 | 3 | 4 | 5 | 6 | 7 | KoPL 引擎 — KoPL 1.0.0 documentation 8 | 9 | 10 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 72 | 73 |
77 | 78 |
79 |
80 |
81 | 88 |
89 |
90 |
91 |
92 | 93 |
94 |

KoPL 引擎

95 |
96 | 97 | 98 |
99 |
100 |
104 | 105 |
106 | 107 |
108 |

© Copyright 2021, KEG.

109 |
110 | 111 | Built with Sphinx using a 112 | theme 113 | provided by Read the Docs. 114 | 115 | 116 |
117 |
118 |
119 |
120 |
121 | 126 | 127 | 128 | -------------------------------------------------------------------------------- /doc/source/_build/html/doc_4_example.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 使用示例 — KoPL 1.0.0 documentation 8 | 9 | 10 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 72 | 73 |
77 | 78 |
79 |
80 |
81 | 88 |
89 |
90 |
91 |
92 | 93 |
94 |

使用示例

95 |
96 | 97 | 98 |
99 |
100 |
104 | 105 |
106 | 107 |
108 |

© Copyright 2021, KEG.

109 |
110 | 111 | Built with Sphinx using a 112 | theme 113 | provided by Read the Docs. 114 | 115 | 116 |
117 |
118 |
119 |
120 |
121 | 126 | 127 | 128 | -------------------------------------------------------------------------------- /doc/source/_build/html/exam_1_input.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 用户输入 — KoPL 1.0.0 documentation 8 | 9 | 10 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 72 | 73 |
77 | 78 |
79 |
80 |
81 | 88 |
89 |
90 |
91 |
92 | 93 |
94 |

用户输入

95 |
96 | 97 | 98 |
99 |
100 |
104 | 105 |
106 | 107 |
108 |

© Copyright 2021, KEG.

109 |
110 | 111 | Built with Sphinx using a 112 | theme 113 | provided by Read the Docs. 114 | 115 | 116 |
117 |
118 |
119 |
120 |
121 | 126 | 127 | 128 | -------------------------------------------------------------------------------- /doc/source/_build/html/exam_2_schema.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | schema 链接 — KoPL 1.0.0 documentation 8 | 9 | 10 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 72 | 73 |
77 | 78 |
79 |
80 |
81 | 88 |
89 |
90 |
91 |
92 | 93 |
94 |

schema 链接

95 |
96 | 97 | 98 |
99 |
100 |
104 | 105 |
106 | 107 |
108 |

© Copyright 2021, KEG.

109 |
110 | 111 | Built with Sphinx using a 112 | theme 113 | provided by Read the Docs. 114 | 115 | 116 |
117 |
118 |
119 |
120 |
121 | 126 | 127 | 128 | -------------------------------------------------------------------------------- /doc/source/_build/html/glossary.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 术语 — KoPL 1.0.0 documentation 8 | 9 | 10 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 72 | 73 |
77 | 78 |
79 |
80 |
81 | 88 |
89 |
90 |
91 |
92 | 93 |
94 |

术语

95 |
96 | 97 | 98 |
99 |
100 |
104 | 105 |
106 | 107 |
108 |

© Copyright 2021, KEG.

109 |
110 | 111 | Built with Sphinx using a 112 | theme 113 | provided by Read the Docs. 114 | 115 | 116 |
117 |
118 |
119 |
120 |
121 | 126 | 127 | 128 | -------------------------------------------------------------------------------- /doc/source/_build/html/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | KoPL-面向知识的复杂问题推理编程语言 — KoPL 1.0.0 documentation 7 | 8 | 9 | 10 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 67 | 68 |
72 | 73 |
74 |
75 |
76 |
    77 |
  • »
  • 78 |
  • KoPL-面向知识的复杂问题推理编程语言
  • 79 |
  • 80 |
  • 81 |
82 |
83 |
84 |
85 |
86 | 87 |
88 |

KoPL-面向知识的复杂问题推理编程语言

89 | 97 |
98 |

快速开始

99 | 103 |
104 |
105 |

更多KoPL样例

106 | 113 |
114 |
115 |

API文档

116 | 119 |
120 |
121 |
122 |

Indices and tables

123 | 128 |
129 | 130 | 131 |
132 |
133 |
136 | 137 |
138 | 139 |
140 |

© Copyright 2021, KEG.

141 |
142 | 143 | Built with Sphinx using a 144 | theme 145 | provided by Read the Docs. 146 | 147 | 148 |
149 |
150 |
151 |
152 |
153 | 158 | 159 | 160 | -------------------------------------------------------------------------------- /doc/source/_build/html/install.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 安装 — KoPL 1.0.0 documentation 8 | 9 | 10 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 67 | 68 |
72 | 73 |
74 |
75 |
76 | 83 |
84 |
85 |
86 |
87 | 88 |
89 |

安装

90 |

KoPL支持Linux (e.g., Ubuntu/CentOS),macOS,Windows。

91 |

其中Linux和macOS的依赖为:

92 |
python >= 3.6
 93 | 
 94 | tqdm >= 4.62
 95 | 
96 |
97 |

Windows对环境的要求为:

98 |
Python >= 3.6
 99 | 
100 | tqdm >= 4.62
101 | 
102 | x86_64处理器
103 | 
104 | Windows10及以上
105 | 
106 |
107 |

KoPL提供pip安装, 下面将展示Ubuntu的安装命令:

108 |
$ sudo apt install python3.7-dev
109 | 
110 | $ python3.7 -m pip install KoPL
111 | 
112 |
113 |

运行下面的代码

114 |
import kopl
115 | from kopl.test.test_example import *
116 | run_test()
117 | 
118 |
119 |

如果测试运行通过,恭喜您已经安装成功。

120 |
121 | 122 | 123 |
124 |
125 |
129 | 130 |
131 | 132 |
133 |

© Copyright 2021, KEG.

134 |
135 | 136 | Built with Sphinx using a 137 | theme 138 | provided by Read the Docs. 139 | 140 | 141 |
142 |
143 |
144 |
145 |
146 | 151 | 152 | 153 | -------------------------------------------------------------------------------- /doc/source/_build/html/intro.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 面向复杂推理问答的程序表示——KoPL — KoPL 1.0.0 documentation 8 | 9 | 10 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 67 | 68 |
72 | 73 |
74 |
75 |
76 |
    77 |
  • »
  • 78 |
  • 面向复杂推理问答的程序表示——KoPL
  • 79 |
  • 80 | View page source 81 |
  • 82 |
83 |
84 |
85 |
86 |
87 | 88 |
89 |

面向复杂推理问答的程序表示——KoPL

90 |

KoPL是一个为复杂推理问答而设计的编程语言。我们可以将自然语言问题表示为由元函数组合而成的KoPL程序,程序运行的结果就是问题的答案。目前,KoPL的27个元函数覆盖对多种知识元素(如概念、实体、关系、属性、修饰符等)的操作,并支持多种问题类型(如计数、事实验证、比较等)的查询。KoPL提供透明的复杂问题推理过程,易于理解和使用。

91 |
92 |
93 |

设计理念

94 |
    95 |
  • 显式、透明的推理过程

  • 96 |
  • 易于理解,便于人机交互

  • 97 |
  • 面向知识库、文本等不同形式的知识,可扩展性强

  • 98 |
99 |
100 | 101 | 102 |
103 |
104 |
108 | 109 |
110 | 111 |
112 |

© Copyright 2021, KEG.

113 |
114 | 115 | Built with Sphinx using a 116 | theme 117 | provided by Read the Docs. 118 | 119 | 120 |
121 |
122 |
123 |
124 |
125 | 130 | 131 | 132 | -------------------------------------------------------------------------------- /doc/source/_build/html/objects.inv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THU-KEG/KoPL/486c07bd83ea32268ff90fa6942cc9f7e1574ae5/doc/source/_build/html/objects.inv -------------------------------------------------------------------------------- /doc/source/_build/html/py-modindex.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Python Module Index — KoPL 1.0.0 documentation 7 | 8 | 9 | 10 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 69 | 70 |
74 | 75 |
76 |
77 |
78 |
    79 |
  • »
  • 80 |
  • Python Module Index
  • 81 |
  • 82 |
  • 83 |
84 |
85 |
86 |
87 |
88 | 89 | 90 |

Python Module Index

91 | 92 |
93 | k 94 |
95 | 96 | 97 | 98 | 100 | 101 | 103 | 106 | 107 | 108 | 111 |
 
99 | k
104 | kopl 105 |
    109 | kopl.kopl 110 |
112 | 113 | 114 |
115 |
116 |
117 | 118 |
119 | 120 |
121 |

© Copyright 2021, KEG.

122 |
123 | 124 | Built with Sphinx using a 125 | theme 126 | provided by Read the Docs. 127 | 128 | 129 |
130 |
131 |
132 |
133 |
134 | 139 | 140 | 141 | -------------------------------------------------------------------------------- /doc/source/_build/html/search.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Search — KoPL 1.0.0 documentation 7 | 8 | 9 | 10 | 11 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 69 | 70 |
74 | 75 |
76 |
77 |
78 |
    79 |
  • »
  • 80 |
  • Search
  • 81 |
  • 82 |
  • 83 |
84 |
85 |
86 |
87 |
88 | 89 | 96 | 97 | 98 |
99 | 100 |
101 | 102 |
103 |
104 |
105 | 106 |
107 | 108 |
109 |

© Copyright 2021, KEG.

110 |
111 | 112 | Built with Sphinx using a 113 | theme 114 | provided by Read the Docs. 115 | 116 | 117 |
118 |
119 |
120 |
121 |
122 | 127 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | -------------------------------------------------------------------------------- /doc/source/_build/html/service.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 查询服务 — KoPL 1.0.0 documentation 8 | 9 | 10 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 67 | 68 |
72 | 73 |
74 |
75 |
76 | 83 |
84 |
85 |
86 |
87 | 88 |
89 |

查询服务

90 |

您可以准备自己的知识库,搭建自己的KoPL引擎来实现复杂推理问答,也可以使用我们为您提供的查询服务,快速开启KoPL之旅~

91 |
92 | 93 | 94 |
95 |
96 |
100 | 101 |
102 | 103 |
104 |

© Copyright 2021, KEG.

105 |
106 | 107 | Built with Sphinx using a 108 | theme 109 | provided by Read the Docs. 110 | 111 | 112 |
113 |
114 |
115 |
116 |
117 | 122 | 123 | 124 | -------------------------------------------------------------------------------- /doc/source/_static/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THU-KEG/KoPL/486c07bd83ea32268ff90fa6942cc9f7e1574ae5/doc/source/_static/.DS_Store -------------------------------------------------------------------------------- /doc/source/conf.py: -------------------------------------------------------------------------------- 1 | # Configuration file for the Sphinx documentation builder. 2 | # 3 | # This file only contains a selection of the most common options. For a full 4 | # list see the documentation: 5 | # https://www.sphinx-doc.org/en/master/usage/configuration.html 6 | 7 | # -- Path setup -------------------------------------------------------------- 8 | 9 | # If extensions (or modules to document with autodoc) are in another directory, 10 | # add these directories to sys.path here. If the directory is relative to the 11 | # documentation root, use os.path.abspath to make it absolute, like shown here. 12 | # 13 | import os 14 | import sys 15 | sys.path.insert(0, os.path.abspath('../python')) 16 | 17 | 18 | # -- Project information ----------------------------------------------------- 19 | 20 | project = 'KoPL' 21 | copyright = '2021, KEG' 22 | author = 'KEG' 23 | 24 | # The full version, including alpha/beta/rc tags 25 | release = '1.0.0' 26 | 27 | 28 | # -- General configuration --------------------------------------------------- 29 | 30 | # Add any Sphinx extension module names here, as strings. They can be 31 | # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom 32 | # ones. 33 | extensions = [ 34 | 'sphinx.ext.autodoc', 35 | 'sphinx.ext.napoleon', 36 | 'sphinx.ext.doctest', 37 | 'sphinx.ext.todo', 38 | 'sphinx.ext.mathjax', 39 | 'sphinx.ext.viewcode', 40 | ] 41 | 42 | # Add any paths that contain templates here, relative to this directory. 43 | templates_path = ['_templates'] 44 | 45 | # List of patterns, relative to source directory, that match files and 46 | # directories to ignore when looking for source files. 47 | # This pattern also affects html_static_path and html_extra_path. 48 | exclude_patterns = [] 49 | 50 | 51 | # -- Options for HTML output ------------------------------------------------- 52 | 53 | # The theme to use for HTML and HTML Help pages. See the documentation for 54 | # a list of builtin themes. 55 | # 56 | html_theme = 'sphinx_rtd_theme' 57 | 58 | # Add any paths that contain custom static files (such as style sheets) here, 59 | # relative to this directory. They are copied after the builtin static files, 60 | # so a file named "default.css" will overwrite the builtin "default.css". 61 | html_static_path = ['_static'] 62 | 63 | html_baseurl = '/' 64 | html_logo = 'logo.png' 65 | html_theme_options = { 66 | 'logo_only': True, 67 | 'display_version': False, 68 | 'collapse_navigation': True, 69 | } 70 | html_show_sourcelink = False 71 | body_max_width = 1600 72 | html_context = {} 73 | -------------------------------------------------------------------------------- /doc/source/demo1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THU-KEG/KoPL/486c07bd83ea32268ff90fa6942cc9f7e1574ae5/doc/source/demo1.png -------------------------------------------------------------------------------- /doc/source/demo10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THU-KEG/KoPL/486c07bd83ea32268ff90fa6942cc9f7e1574ae5/doc/source/demo10.png -------------------------------------------------------------------------------- /doc/source/demo11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THU-KEG/KoPL/486c07bd83ea32268ff90fa6942cc9f7e1574ae5/doc/source/demo11.png -------------------------------------------------------------------------------- /doc/source/demo12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THU-KEG/KoPL/486c07bd83ea32268ff90fa6942cc9f7e1574ae5/doc/source/demo12.png -------------------------------------------------------------------------------- /doc/source/demo13.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THU-KEG/KoPL/486c07bd83ea32268ff90fa6942cc9f7e1574ae5/doc/source/demo13.png -------------------------------------------------------------------------------- /doc/source/demo2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THU-KEG/KoPL/486c07bd83ea32268ff90fa6942cc9f7e1574ae5/doc/source/demo2.png -------------------------------------------------------------------------------- /doc/source/demo3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THU-KEG/KoPL/486c07bd83ea32268ff90fa6942cc9f7e1574ae5/doc/source/demo3.png -------------------------------------------------------------------------------- /doc/source/demo4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THU-KEG/KoPL/486c07bd83ea32268ff90fa6942cc9f7e1574ae5/doc/source/demo4.png -------------------------------------------------------------------------------- /doc/source/demo5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THU-KEG/KoPL/486c07bd83ea32268ff90fa6942cc9f7e1574ae5/doc/source/demo5.png -------------------------------------------------------------------------------- /doc/source/demo6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THU-KEG/KoPL/486c07bd83ea32268ff90fa6942cc9f7e1574ae5/doc/source/demo6.png -------------------------------------------------------------------------------- /doc/source/demo7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THU-KEG/KoPL/486c07bd83ea32268ff90fa6942cc9f7e1574ae5/doc/source/demo7.png -------------------------------------------------------------------------------- /doc/source/demo8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THU-KEG/KoPL/486c07bd83ea32268ff90fa6942cc9f7e1574ae5/doc/source/demo8.png -------------------------------------------------------------------------------- /doc/source/demo9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THU-KEG/KoPL/486c07bd83ea32268ff90fa6942cc9f7e1574ae5/doc/source/demo9.png -------------------------------------------------------------------------------- /doc/source/index.rst: -------------------------------------------------------------------------------- 1 | .. KoPL documentation master file, created by 2 | sphinx-quickstart on Mon Oct 4 11:12:27 2021. 3 | You can adapt this file completely to your liking, but it should at least 4 | contain the root `toctree` directive. 5 | 6 | KoPL-面向知识的复杂问题推理编程语言 7 | ================================ 8 | .. toctree:: 9 | :maxdepth: 1 10 | :caption: KoPL入门 11 | 12 | 0_intro 13 | 1_knowledge 14 | 2_function 15 | 16 | .. toctree:: 17 | :maxdepth: 1 18 | :caption: 快速开始 19 | 20 | 3_install 21 | 4_helloworld 22 | 23 | .. toctree:: 24 | :maxdepth: 1 25 | :caption: 更多KoPL样例 26 | 27 | 5_example 28 | 6_service 29 | 30 | .. toctree:: 31 | :maxdepth: 1 32 | :caption: API文档 33 | 34 | 7_kopl 35 | 36 | 37 | Indices and tables 38 | ================== 39 | 40 | * :ref:`genindex` 41 | * :ref:`modindex` 42 | * :ref:`search` 43 | -------------------------------------------------------------------------------- /doc/source/knowledge_element.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THU-KEG/KoPL/486c07bd83ea32268ff90fa6942cc9f7e1574ae5/doc/source/knowledge_element.jpg -------------------------------------------------------------------------------- /doc/source/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THU-KEG/KoPL/486c07bd83ea32268ff90fa6942cc9f7e1574ae5/doc/source/logo.png -------------------------------------------------------------------------------- /src/kopl/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THU-KEG/KoPL/486c07bd83ea32268ff90fa6942cc9f7e1574ae5/src/kopl/__init__.py -------------------------------------------------------------------------------- /src/kopl/test/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/THU-KEG/KoPL/486c07bd83ea32268ff90fa6942cc9f7e1574ae5/src/kopl/test/__init__.py -------------------------------------------------------------------------------- /src/kopl/util.py: -------------------------------------------------------------------------------- 1 | import json 2 | import os 3 | from collections import defaultdict 4 | from queue import Queue 5 | from datetime import date 6 | from tqdm import tqdm 7 | 8 | def comp(a, b, op): 9 | """ 10 | Args: 11 | - a (ValueClass): attribute value of a certain entity 12 | - b (ValueClass): comparison target 13 | - op: =/>/': 28 | return a > b 29 | elif op == '!=': 30 | return a != b 31 | else: 32 | raise TypeError('Unsupported operator. Support =/>/ other.value 114 | elif self.type == 'year': 115 | other_value = other.value if other.type == 'year' else other.value.year 116 | return self.value > other_value 117 | elif self.type == 'date': 118 | if other.type == 'year': 119 | return self.value.year > other.value 120 | else: 121 | return self.value > other.value 122 | 123 | def __str__(self): 124 | if self.type == 'string': 125 | return self.value 126 | elif self.type == 'quantity': 127 | if self.value - int(self.value) < 1e-5: 128 | v = int(self.value) 129 | else: 130 | v = self.value 131 | return '{} {}'.format(v, self.unit) if self.unit != '1' else str(v) 132 | elif self.type == 'year': 133 | return str(self.value) 134 | elif self.type == 'date': 135 | return self.value.isoformat() 136 | 137 | def __hash__(self): 138 | return hash(str(self)) --------------------------------------------------------------------------------