Source: Neosematics

← Rendered

markdown source:

---
description: (n10s) knowledge graphs in neo4j
title: Neosematics
tags: data-bases graphs machine-learning knowledge-graphs
---
(n10s) is a plugin that enables the use of RDF and its associated vocabularies like (OWL, RDFS, SKOS and others) in [[neo4j]].

## Basic flow

### 0. Pre-req: Constraint Creation

```sql
CREATE CONSTRAINT n10s_unique_uri FOR (r:Resource) REQUIRE r.uri IS UNIQUE
```

### 1. Creating a Graph Configuration

Before any RDF import operation a `GraphConfig` needs to be created. Here we define the way the RDF data is persisted in Neo4j. We'll find things like

| Param        | Values           | Desc  |
| :------------- |:-------------|:-----|
| handleVocabUris     | "SHORTEN","KEEP","SHORTEN_STRICT","MAP"|  how namespaces are  handled |
| handleMultival     | "OVERWRITE","ARRAY"      | how multivalued properties are handled |
| handleRDFTypes | "LABELS","NODES","LABELS_AND_NODES"      |  how RDF datatypes are handled |
| multivalPropList | [ list of predicate uris ] |  |
| ...| ...|...|

Check the complete list in [the reference](https://neo4j.com/labs/neosemantics/4.3/reference/).

You can create a graph config with all the defaults like this:

```sql
call n10s.graphconfig.init()
```

Or customize it by passing a map with your options:

```sql
call n10s.graphconfig.init( { handleMultival: "ARRAY",
                              multivalPropList: ["http://voc1.com#pred1", "http://voc1.com#pred2"],
                              keepLangTag: true })
```

### 2. Importing RDF data

Once the Graph config is created we can import data from a url using `fetch`:

```sql
call n10s.rdf.import.fetch( "https://raw.githubusercontent.com/jbarrasa/neosemantics/3.5/docs/rdf/nsmntx.ttl",
                            "Turtle")
```

Or pass it as a parameter using `inline`:

```sql
with '
@prefix neo4voc: <http://neo4j.org/vocab/sw#> .
@prefix neo4ind: <http://neo4j.org/ind#> .

neo4ind:nsmntx3502 neo4voc:name "NSMNTX" ;
a neo4voc:Neo4jPlugin ;
neo4voc:runsOn neo4ind:neo4j355 .

neo4ind:apoc3502 neo4voc:name "APOC" ;
a neo4voc:Neo4jPlugin ;
neo4voc:runsOn neo4ind:neo4j355 .

neo4ind:graphql3502 neo4voc:name "Neo4j-GraphQL" ;
a neo4voc:Neo4jPlugin ;
neo4voc:runsOn neo4ind:neo4j355 .

neo4ind:neo4j355 neo4voc:name "neo4j" ;
a neo4voc:GraphPlatform , neo4voc:AwesomePlatform .

' as  payload

call n10s.rdf.import.inline( payload, "Turtle") yield terminationStatus, triplesLoaded, triplesParsed, namespaces
return terminationStatus, triplesLoaded, triplesParsed, namespaces
```

It is possible to pass some request specific parameters like headerParams, commitSize, languageFilter...
(also found [the reference](https://neo4j.com/labs/neosemantics/4.3/reference/))

### 3. Importing Ontologies, QuadRDF, etc

Same naming scheme applies...

```sql
call n10s.onto.import.fetch(...)
```

Use autocompletion to discover the different procedures.

Смотри еще:

- [все ресурсы по библиотеке](https://neo4j.com/labs/neosemantics/)
- [гитхаб](https://github.com/neo4j-labs/neosemantics)
- [docs and user guide](https://neo4j.com/labs/neosemantics/4.3/)
- [how to import wikidata](https://neo4j.com/labs/neosemantics/how-to-guide/)
- [Neosemantics Graph App](https://neo4j.com/labs/neosemantics/graph-app/) (addon to neo4j browser)

Примеры:

- [Tutorial: Build a Knowledge Graph using NLP and Ontologies](https://neo4j.com/developer/graph-data-science/build-knowledge-graph-nlp-ontologies/)
- [The fashion Knowledge Graph. Inferencing with Ontologies in Neo4j](https://jbarrasa.com/2019/11/25/quickgraph9-the-fashion-knowledge-graph-inferencing-with-ontologies-in-neo4j/)
- [Enrich your Neo4j Knowledge Graph by querying Wikidata](https://jbarrasa.com/2019/12/05/quickgraph10-enrich-your-neo4j-knowledge-graph-by-querying-wikidata/)
- [Importing RDF data into Neo4j](https://jbarrasa.com/2016/06/07/importing-rdf-data-into-neo4j/)
- [Creating a schema.org linked data endpoint on Neo4j](https://jbarrasa.com/2018/10/18/quickgraph7-creating-a-schema-org-linked-data-endpoint-on-neo4j-in/)
- [блог майнтенера](https://jbarrasa.com/)

- [[neo4j]]
- [[neo4j-apoc]]
- [[neo4j-ml]]
- [[python-api-neo4j]]
- [[cypher]]
- [[sparql]]
- [[semantic-web]]
- [[rdf]]
- [[owl]]
- [[knowledge-graphs]]


[neo4j]: neo4j "Neo4j graph data base"
[neo4j-apoc]: neo4j-apoc "Neo4j APOC библиотека"
[neo4j-ml]: neo4j-ml "Machine learning in Neo4j"
[python-api-neo4j]: python-api-neo4j "Python api for neo4j"
[cypher]: cypher "Cypher query language"
[sparql]: sparql "SPARQL"
[semantic-web]: semantic-web "Semantic web"
[rdf]: rdf "RDF"
[owl]: owl "OWL ontology"
[knowledge-graphs]: ../lists/knowledge-graphs "Knowledge graphs"


[neo4j]: neo4j "Neo4j graph data base"
[neo4j]: neo4j "Neo4j graph data base"
[neo4j-apoc]: neo4j-apoc "Neo4j APOC библиотека"
[neo4j-ml]: neo4j-ml "Machine learning in Neo4j"
[python-api-neo4j]: python-api-neo4j "Python api for neo4j"
[cypher]: cypher "Cypher query language"
[sparql]: sparql "SPARQL"
[semantic-web]: semantic-web "Semantic web"
[rdf]: rdf "RDF"
[owl]: owl "OWL ontology"
[knowledge-graphs]: ../lists/knowledge-graphs "Knowledge graphs"