<commit_before>package org.neo4j.neometa.structure;

import org.neo4j.api.core.Node;
import org.neo4j.api.core.Transaction;
import org.neo4j.neometa.MetaTestCase;

public class TestOverall extends MetaTestCase
{
	public void testSome()
	{
		Transaction tx = neo().beginTx();
		try
		{
			txTestSome();
			tx.success();
		}
		finally
		{
			tx.finish();
		}
	}
	
	private void txTestSome()
	{
		Node rootNode = neo().createNode();
		MetaStructure structure = new MetaStructure( neo(), rootNode );
		
		assertEquals( 0, structure.getNamespaces().size() );
		MetaStructureNamespace namespace = structure.getGlobalNamespace();
		assertNull( namespace.getName() );
		assertEquals( 1, structure.getNamespaces().size() );
		assertEquals( namespace, structure.getGlobalNamespace() );
		
		assertNull( structure.getNamespace( "something",
			false ) );
		MetaStructureNamespace anotherNamespace = structure.getNamespace(
			"something", true );
		assertNotNull( anotherNamespace );
		
		assertEquals( 0, namespace.getMetaClasses().size() );
		assertEquals( 0, namespace.getMetaProperties().size() );
		assertNull( namespace.getMetaClass( "http://test#Thing", false ) );
		MetaStructureClass thingClass =
			namespace.getMetaClass( "http://test#Thing", true );
		assertNotNull( thingClass );
		assertNotNull( namespace.getMetaClass( "http://test#Thing", false ) );
		assertEquals( 1, namespace.getMetaClasses().size() );
		assertEquals( 0, namespace.getMetaProperties().size() );
		
		MetaStructureClass phoneClass =
			namespace.getMetaClass( "http://test#Phone", true );
		assertEquals( 2, namespace.getMetaClasses().size() );
		thingClass.getDirectSubs().add( phoneClass );
		MetaStructureProperty phoneTypeProperty =
			namespace.getMetaProperty( "http://test#phoneType", true );
		assertEquals( 1, namespace.getMetaProperties().size() );
		phoneClass.getProperties().add( phoneTypeProperty );
		MetaStructureProperty phoneNumberProperty =
			namespace.getMetaProperty( "http://test#phoneNumber", true );
		assertEquals( 2, namespace.getMetaProperties().size() );
		phoneClass.getProperties().add( phoneNumberProperty );
		
		MetaStructureClass personClass =
			namespace.getMetaClass( "http://test#Person", true );
		personClass.getDirectSupers().add( thingClass );
		MetaStructureProperty nameProperty =
			namespace.getMetaProperty( "http://test#name", true );
		nameProperty.setRange( new DatatypeClassRange( String.class ) );
		assertEquals( DatatypeClassRange.class,
			nameProperty.getRange().getClass() );
		assertEquals( String.class, ( ( DatatypeClassRange )
			nameProperty.getRange() ).getRangeClass() );
		MetaStructureProperty givenNameProperty =
			namespace.getMetaProperty( "http://test#givenName", true );
		nameProperty.getDirectSubs().add( givenNameProperty );
		MetaStructureProperty phoneProperty =
			namespace.getMetaProperty( "http://test#phone", true );
		phoneProperty.setRange( new MetaStructureClassRange( phoneClass ) );
		
		personClass.getProperties().add( givenNameProperty );
		
		MetaStructureClass userClass =
			namespace.getMetaClass( "http://test#User", true );
		personClass.getDirectSubs().add( userClass );
		assertTrue( personClass.isSubOf( thingClass ) );
		assertTrue( userClass.isSubOf( personClass ) );
		assertTrue( userClass.isSubOf( thingClass ) );
		assertFalse( userClass.isSubOf( phoneClass ) );
		
		Node person1 = neo().createNode();
		Node person2 = neo().createNode();
		assertCollection( personClass.getInstances() );
		personClass.getInstances().add( person1 );
		assertCollection( personClass.getInstances(), person1 );
		personClass.getInstances().add( person2 );
		assertCollection( personClass.getInstances(), person1, person2 );
		
		personClass.getInstances().remove( person2 );
		assertCollection( personClass.getInstances(), person1 );
		neo().getNodeById( person2.getId() );
	}
}<commit_msg>Cleans up after the tests<commit_after>package org.neo4j.neometa.structure;

import java.util.Collection;
import java.util.HashSet;

import org.neo4j.api.core.Node;
import org.neo4j.api.core.Relationship;
import org.neo4j.api.core.Transaction;
import org.neo4j.neometa.MetaTestCase;

public class TestOverall extends MetaTestCase
{
	public void testSome()
	{
		Transaction tx = neo().beginTx();
		try
		{
			txTestSome();
			tx.success();
		}
		finally
		{
			tx.finish();
		}
	}
	
	private void txTestSome()
	{
		Node rootNode = neo().createNode();
		MetaStructure structure = new MetaStructure( neo(), rootNode );
		
		assertEquals( 0, structure.getNamespaces().size() );
		MetaStructureNamespace namespace = structure.getGlobalNamespace();
		assertNull( namespace.getName() );
		assertEquals( 1, structure.getNamespaces().size() );
		assertEquals( namespace, structure.getGlobalNamespace() );
		
		assertNull( structure.getNamespace( "something",
			false ) );
		MetaStructureNamespace anotherNamespace = structure.getNamespace(
			"something", true );
		assertNotNull( anotherNamespace );
		
		assertEquals( 0, namespace.getMetaClasses().size() );
		assertEquals( 0, namespace.getMetaProperties().size() );
		assertNull( namespace.getMetaClass( "http://test#Thing", false ) );
		MetaStructureClass thingClass =
			namespace.getMetaClass( "http://test#Thing", true );
		assertNotNull( thingClass );
		assertNotNull( namespace.getMetaClass( "http://test#Thing", false ) );
		assertEquals( 1, namespace.getMetaClasses().size() );
		assertEquals( 0, namespace.getMetaProperties().size() );
		
		MetaStructureClass phoneClass =
			namespace.getMetaClass( "http://test#Phone", true );
		assertEquals( 2, namespace.getMetaClasses().size() );
		thingClass.getDirectSubs().add( phoneClass );
		MetaStructureProperty phoneTypeProperty =
			namespace.getMetaProperty( "http://test#phoneType", true );
		assertEquals( 1, namespace.getMetaProperties().size() );
		phoneClass.getProperties().add( phoneTypeProperty );
		MetaStructureProperty phoneNumberProperty =
			namespace.getMetaProperty( "http://test#phoneNumber", true );
		assertEquals( 2, namespace.getMetaProperties().size() );
		phoneClass.getProperties().add( phoneNumberProperty );
		
		MetaStructureClass personClass =
			namespace.getMetaClass( "http://test#Person", true );
		personClass.getDirectSupers().add( thingClass );
		MetaStructureProperty nameProperty =
			namespace.getMetaProperty( "http://test#name", true );
		nameProperty.setRange( new DatatypeClassRange( String.class ) );
		assertEquals( DatatypeClassRange.class,
			nameProperty.getRange().getClass() );
		assertEquals( String.class, ( ( DatatypeClassRange )
			nameProperty.getRange() ).getRangeClass() );
		MetaStructureProperty givenNameProperty =
			namespace.getMetaProperty( "http://test#givenName", true );
		nameProperty.getDirectSubs().add( givenNameProperty );
		MetaStructureProperty phoneProperty =
			namespace.getMetaProperty( "http://test#phone", true );
		phoneProperty.setRange( new MetaStructureClassRange( phoneClass ) );
		
		personClass.getProperties().add( givenNameProperty );
		
		MetaStructureClass userClass =
			namespace.getMetaClass( "http://test#User", true );
		personClass.getDirectSubs().add( userClass );
		assertTrue( personClass.isSubOf( thingClass ) );
		assertTrue( userClass.isSubOf( personClass ) );
		assertTrue( userClass.isSubOf( thingClass ) );
		assertFalse( userClass.isSubOf( phoneClass ) );
		
		Node person1 = neo().createNode();
		Node person2 = neo().createNode();
		assertCollection( personClass.getInstances() );
		personClass.getInstances().add( person1 );
		assertCollection( personClass.getInstances(), person1 );
		personClass.getInstances().add( person2 );
		assertCollection( personClass.getInstances(), person1, person2 );
		
		personClass.getInstances().remove( person2 );
		assertCollection( personClass.getInstances(), person1 );
		neo().getNodeById( person2.getId() );
		removeNodeAndThoseConnectedWith( new HashSet<Node>(),
			new HashSet<Relationship>(), rootNode );
	}
	
	private void removeNodeAndThoseConnectedWith( Collection<Node> deletedNodes,
		Collection<Relationship> deletedRels, Node node )
	{
		for ( Relationship rel : node.getRelationships() )
		{
			Node sub = rel.getOtherNode( node );
			if ( deletedRels.add( rel ) )
			{
				rel.delete();
			}
			if ( deletedNodes.add( sub ) )
			{
				removeNodeAndThoseConnectedWith( deletedNodes, deletedRels,
					sub );
			}
		}
		node.delete();
	}
}
{'fraction_non_alphanumeric': 0.13243922883487008, 'fraction_numerical': 0.005628068494791043, 'mean_word_length': 5.118681318681318, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6269714', 'n_tokens_mistral': 2664, 'n_tokens_neox': 2359, 'n_words': 455}