> For the complete documentation index, see [llms.txt](https://virtualfactory.gitbook.io/vlft/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://virtualfactory.gitbook.io/vlft/kb/fdm/sparql-queries.md).

# SPARQL Queries

[SPARQL ](https://www.w3.org/TR/sparql11-query/)is a [W3C ](https://www.w3.org)query language standard to retrieve and manipulate data stored in Resource Description Framework (RDF) format, thus including OWL ontologies.

The use of SPARQL queries asks for a SPARQL Endpoint, i.e. a server that can handle HTTP requests. SPARQL Endpoints are typically provided by [RDF stores](/vlft/kb/instantiation/datarepo/remote.md#rdf-store).

This section presents examples of SPARQL Queries tailored for the [Factory Data Model](/vlft/kb/fdm.md). These examples must be intended as templates that can be customized by [specifying RDF Datasets](https://www.w3.org/TR/sparql11-query/#specifyingDataset).

The full set of SPARQL queries is available in [this folder](https://github.com/difactory/repository/tree/main/sparql).

* [Get part types](/vlft/kb/fdm/sparql-queries.md#get-part-types)
* [Get process plans](/vlft/kb/fdm/sparql-queries.md#get-process-plans)

### Get Parts and Part Types

```
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> 
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> 
PREFIX fa: <https://w3id.org/ontoeng/factory#> 
SELECT DISTINCT ?parttype ?part ?itsClass
WHERE { 
	{
		?itsClass rdfs:subClassOf* fa:ArtifactType . 
		?parttype rdf:type ?itsClass .
	}
	UNION{
		?itsClass rdfs:subClassOf* fa:Artifact . 
		?part rdf:type ?itsClass .
	}
}
```

### Get Process Plans of Parts/Part types

```
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> 
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> 
PREFIX ifc: <https://standards.buildingsmart.org/IFC/DEV/IFC4/ADD1/OWL#> 
PREFIX ifcext: <https://w3id.org/ontoeng/IFC4_ADD1_extension#> 
PREFIX factory: <https://w3id.org/ontoeng/factory#> 
select distinct ?parttype ?pplan 
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> 
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> 
PREFIX ifcext: <https://w3id.org/ontoeng/IFC4_ADD1_extension#> 
PREFIX fa: <https://w3id.org/ontoeng/factory#> 
select distinct ?parttype ?part ?pplan 
WHERE { 

	?pplan rdf:type/rdfs:subClassOf* fa:TaskSelect .
	
	{
		?parttype ifcext:hasAssignedObject|^ifcext:hasAssignmentTo ?pplan .
		?parttype rdf:type/rdfs:subClassOf* fa:ArtifactType .
	}
	UNION{
		{
			?part ifcext:isDefinedByType ?parttype .
			?parttype ifcext:hasAssignedObject|^ifcext:hasAssignmentTo ?pplan .
		}
		UNION{
			?part ifcext:hasAssignedObject|^ifcext:hasAssignmentTo ?pplan .
		}
		?part rdf:type/rdfs:subClassOf* fa:Artifact . 
	}
}
```
