Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

父亲定义Rule继承问题 #426

Open
ganhb opened this issue Dec 18, 2024 · 0 comments
Open

父亲定义Rule继承问题 #426

ganhb opened this issue Dec 18, 2024 · 0 comments
Assignees

Comments

@ganhb
Copy link

ganhb commented Dec 18, 2024

Q:如何实现在父亲本体上定义一个rule(可能是关系计算规则或者属性计算规则),其所有层子类应该都继承这个规则,而无须在子类重复定义该规则。

假设有结构
image
先申明不按建模最佳实践来设计一个分类解决,我想用继承方式;
我弄个schema文件如下:

FilmStat(电影明星):ConceptType
    hypernymPredicate: isA

Person(人):ConceptType
    hypernymPredicate: isA

ArtificialObject(作品): ConceptType
    hypernymPredicate: isA

FilmDirector(导演):EntityType
    properties:
        IND#belongTo(属于):Person
        age(年龄):Integer
        gender(性别):Text

PopularFilmStat(流行电影明星):EntityType
    properties:
        IND#belongTo(属于):FilmStat
        age(年龄):Integer
        gender(性别):Text

Film(电影):EntityType
    properties:
        filmBudget(投入):Integer
        filmGross(票房):Integer
        IND#belongTo(属于):ArtificialObject
    relations:
        starOfFilm(主演):FilmStat
        directOfFilm(被导演):FilmDirector
        oldestOfStat(xx明星):FilmStat
            rule:[[
                       STRUCTURE {
                                (o)
                            }
                            CONSTRAINT {
                               R2("xx"):  o.name in ["张三"]
                            }
                      ]]

生成的图如下:

image

这种多层级继承的结构,spg如何定义继承schema

如果用belongTo来定义,不符合继承逻辑,并且它要求 a concept type to conform to the definition必须是概念类型,但是概念类型没办法继承且不能定义属性和规则。

如果用isA,则没办法多次继承,形如图上应该”电影明星“isA”人“;

后面在查找白皮书,看到4.3.1.1原文内容如下:

subClassOf 谓词通过定义节点类型之间的层级关系来补充类型继承的语义,在定义节点类型 Class 时,在后面跟上 SUBCLASSOF 关键字引导的类型名称即可实现继承。 
// 定义 User 类的两个子类 CREATE ENTITY TYPE (Person {age INT, OPTIONAL father Person}) SUBCLASSOF (User); CREATE ENTITY TYPE (LegalPerson {amount INT, legalId STRING}) SUBCLASSOF (User);

在v0.5的schema上如何定义subClassOf,或者怎么实现继承关系;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants