Triple Edge 是以 (Subject, Property, Object) 形式表达关系/属性的 Edge 类型。

双模式设计

  • 基本模式(4字): PropCode 0~62(Top 63 属性)
  • 扩展模式(5字): PropCode=63时覆盖全部 P-ID(语义对齐16位)

基本模式(4字 = 64位)

1st WORD (16位)
┌────────────────────┬────────────────────┐
│      Prefix        │     PropCode       │
│      10bit         │       6bit         │
└────────────────────┴────────────────────┘

2nd WORD: Edge TID (16位)
3rd WORD: Subject TID (16位)
4th WORD: Object TID (16位)
字段说明
Prefix101100 000 001
PropCode60~62: Top 63 属性, 63: 扩展模式
Edge TID16此 Edge 的 TID
Subject TID16主语 Entity/Node TID
Object TID16宾语 Entity/Node/Quantity TID

扩展模式(5字 = 80位)

PropCode 为63时,第3字追加16位 P-ID。

1st WORD: [Prefix 10bit] + [PropCode=63 6bit]
2nd WORD: Edge TID (16位)
3rd WORD: P-ID 语义对齐 (16位)
4th WORD: Subject TID (16位)
5th WORD: Object TID (16位)

Top 63 属性(PropCode 0~62)

基于维基数据使用频率选定的属性。

分类/类型(Code 0~7)

CodeP-ID属性名说明
0P31instance of~的实例
1P279subclass of~的子类
2P361part of~的部分
3P527has part包含~
4P1552has quality属性/特性
5P460same as相同
6P1889different from不同
7P156followed by后续

空间/位置(Code 8~15)

CodeP-ID属性名说明
8P17country国家
9P131located in位置(行政区)
10P276location位置(地点)
11P625coordinate坐标
12P30continent大洲
13P36capital首都
14P150contains包含(地区)
15P206located next to相邻水域

时间(Code 16~23)

CodeP-ID属性名说明
16P569date of birth出生日期
17P570date of death逝世日期
18P571inception成立日期
19P576dissolved解散日期
20P577publication date发布日期
21P580start time开始时间
22P582end time结束时间
23P585point in time时间点

人物基本(Code 24~31)

CodeP-ID属性名说明
24P19place of birth出生地
25P20place of death逝世地
26P21sex or gender性别
27P27citizenship国籍
28P735given name
29P734family name
30P1559name in native language本名
31P742pseudonym笔名/艺名

关系/隶属(Code 32~39)

CodeP-ID属性名说明
32P22father父亲
33P25mother母亲
34P26spouse配偶
35P40child子女
36P3373sibling兄弟姐妹
37P463member of所属
38P108employer雇主
39P1027conferred by授予机构

职业/活动(Code 40~47)

CodeP-ID属性名说明
40P106occupation职业
41P39position held职位
42P69educated at学历
43P101field of work领域
44P1344participant in参加(事件)
45P166award received获奖
46P800notable work代表作
47P1412languages spoken使用语言

媒体/标识(Code 48~55)

CodeP-ID属性名说明
48P18image图像
49P154logo标志
50P41flag image国旗/旗帜
51P373Commons category维基媒体
52P856official website官方网站
53P214VIAF IDVIAF
54P227GND IDGND
55P213ISNIISNI

作品/创作(Code 56~62)

CodeP-ID属性名说明
56P50author作者
57P57director导演
58P86composer作曲家
59P175performer演奏者/歌手
60P136genre类型
61P364original language原语言
62P123publisher出版社

Code 63 作为扩展模式标记保留。

PropCode 总览

┌─────────────────────────────────────────────┐
│  0~7:   分类/类型 (P31, P279, ...)          │
│  8~15:  空间/位置 (P17, P131, ...)          │
│  16~23: 时间 (P569, P570, ...)              │
│  24~31: 人物基本 (P19, P20, ...)            │
│  32~39: 关系/隶属 (P22, P25, ...)           │
│  40~47: 职业/活动 (P106, P39, ...)          │
│  48~55: 媒体/标识 (P18, P856, ...)          │
│  56~62: 作品/创作 (P50, P57, ...)           │
├─────────────────────────────────────────────┤
│  63: 扩展模式标记                            │
└─────────────────────────────────────────────┘

示例

基本模式:“Apple是一家公司”

P31 (instance of) → PropCode = 0

Triple Edge:
  1st: [1100 000 001] + [000000]  - Prefix + PropCode 0
  2nd: [TID: 0x0101]              - Edge TID
  3rd: [TID: 0x0010]              - Apple (Subject)
  4th: [TID: 0x0020]              - 公司 (Object)

总计: 4字

扩展模式:“埃菲尔铁塔的高度是330m”

P2048 (height) → 不在 Top 63 中 → 扩展模式

Triple Edge:
  1st: [1100 000 001] + [111111]  - Prefix + Ext(63)
  2nd: [TID: 0x0102]              - Edge TID
  3rd: [0xA800]                   - P2048 语义对齐
  4th: [TID: 0x0030]              - 埃菲尔铁塔 (Subject)
  5th: [TID: 0x0050]              - 330m Quantity (Object)

总计: 5字

解析

def parse_triple_edge(data: bytes) -> dict:
    word1 = int.from_bytes(data[0:2], 'big')

    prefix = word1 >> 6
    assert prefix == 0b1100000001, "Not Triple Edge"

    prop_code = word1 & 0x3F

    if prop_code < 63:
        # 基本模式 (4字)
        return {
            'mode': 'basic',
            'prop_code': prop_code,
            'edge_tid': int.from_bytes(data[2:4], 'big'),
            'subject_tid': int.from_bytes(data[4:6], 'big'),
            'object_tid': int.from_bytes(data[6:8], 'big'),
            'words': 4
        }
    else:
        # 扩展模式 (5字)
        return {
            'mode': 'extended',
            'p_id': int.from_bytes(data[4:6], 'big'),
            'edge_tid': int.from_bytes(data[2:4], 'big'),
            'subject_tid': int.from_bytes(data[6:8], 'big'),
            'object_tid': int.from_bytes(data[8:10], 'big'),
            'words': 5
        }