Neo4j SDN国际化

ale*_*oid 2 neo4j spring-data-neo4j-4

我有以下SDN 4实体:

Decision,CharacteristicValue:

@NodeEntity
public class Value {

    private final static String SET_FOR = "SET_FOR";
    private final static String SET_ON = "SET_ON";

    @Relationship(type = SET_FOR, direction = Relationship.OUTGOING)
    private Decision decision;

    @Relationship(type = SET_ON, direction = Relationship.OUTGOING)
    private Characteristic characteristic;

    @Index(unique = false)
    private Object value;

    private String description;
...

}
Run Code Online (Sandbox Code Playgroud)

我想补充的多语言支持Value,以便能够提供一个Value.valueValue.description在任何语言.

你能用一种正确的方法来展示一种正确的方法吗?

我是否应该在那里添加一个额外的节点(与Value节点相关联),它将代表每种新语言的值/描述对,或者可以通过在现有Value节点内引入新的特定于语言的属性来完成?

Eri*_*erg 5

通过Spring Data Neo4j添加多语言支持有很多选项.

https://graphaware.com/neo4j/2016/09/29/internationalization-with-spring-neo4j.html(由我撰写)中概述的一种方法可以帮助您在实施解决方案方面领先一步.

按照博客的SDN项目设置和配置后,您Value可以使用Cypher定义两个MessageDefinitions,一个代码Value.value与另一个代码匹配的代码Value.description.走这条路线,您实际上是添加了MessageDefinitionValue节点相关联的额外节点(即:节点),该节点用国际化和本地化的消息表示值和描述.换句话说,Value值和描述属性用作相应MessageDefinition节点的键.

MessageDefinitions在Neo4j中配置和期望定义项目后,您可以在控制器或服务中使用以下代码来获取国际化和本地化的值:

    Value value = valueRepository.findOne(id);

    Object arguments[] = new Object[] {};
    Locale locale = LocaleContextHolder.getLocale();

    String valueMessageKey = value.getValue();
    String i18Value = messageSource.getMessage(valueMessageKey, arguments, "defaultValue", locale);

    String descriptionMessageKey = value.getDescription();
    String i18Description = messageSource.getMessage(descriptionMessageKey, arguments, "defaultDescription", locale);

    System.out.println("i18Value: " + i18Value);
    System.out.println("i18Description: " + i18Description);
Run Code Online (Sandbox Code Playgroud)

值得注意的是,这种方法的缺点在于,MessageDefinitionValue对象是通过匹配的节点属性相关联的,而不是基础的Neo4j关系,后者效率较低,因为它没有利用Neo4j的核心优势(即:关系).虽然这是需要注意的事项,但如果是实际问题则取决于您的使用案例.如果它是交易破坏者,可以修改CypherMessageSource项目以更符合您的要求.

查看示例代码,请注意您可能希望将Value.value属性的类型从Object更改为String,以确保它是可靠的密钥.