# Pruning

## Merge Duplicated Nodes

```
MATCH
   (node)
WITH
   node.fqn AS name,
   COLLECT(node) AS nodes,
   COUNT(*) AS count
WHERE
   count > 1
CALL
   apoc.refactor.mergeNodes(nodes, {mergeRels: true}) YIELD node
RETURN
   node
```

## Merge Duplicated Classes

```
MATCH
   (left:Type),
   (right:Type)
WHERE
   left.fqn = right.fqn
   AND id(left) < id(right)
WITH
   [left,right] as nodes
CALL
   apoc.refactor.mergeNodes(nodes) YIELD node
RETURN
   node
```

## Merge Duplicated Methods

```
MATCH
   (class)-[:DECLARES]->(method:Method)
WITH
   class.fqn as class,
   method.name AS method,
   COLLECT(method) AS nodes,
   COUNT(*) AS count
WHERE
   count > 1
CALL
   apoc.refactor.mergeNodes(nodes, {mergeRels: true}) YIELD node
RETURN
   node
```

## Merge Duplicated Relationships

```
MATCH
   (node)-[r]->(related)
WITH
   node.fqn AS name,
   related.fqn AS related,
   type(r) AS relType,
   COLLECT(r) AS rels,
   COUNT(*) AS count
WHERE
   count > 1
CALL
   apoc.refactor.mergeRelationships(rels) YIELD rel
RETURN
   rel
```

## Delete Duplicated Relationships

```
MATCH
   (left:Type)-[r]->(right:Type)
WITH
   left,
   right,
   type(r) as type,
   collect(r) as rels
WHERE
   size(rels) > 1
UNWIND
   tail(rels) as rel
DELETE
   rel
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://bernardo.gitbook.io/development-docs-java/jqassistant/queries/pruning.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
