Java Code Examples for org.jgrapht.graph.Pseudograph#addEdge()

The following examples show how to use org.jgrapht.graph.Pseudograph#addEdge() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AssociativeLogicManagerTest.java    From Knowage-Server with GNU Affero General Public License v3.0 4 votes vote down vote up
@Test
public void testProcessTwoDatasetsOneSimpleAssociation() {
	Pseudograph<String, LabeledEdge<String>> graph = new Pseudograph<>(
			new ClassBasedEdgeFactory<String, LabeledEdge<String>>((Class<LabeledEdge<String>>) (Object) LabeledEdge.class));
	graph.addVertex(DS_STORE);
	graph.addVertex(DS_SALES_FACT_1998);
	LabeledEdge<String> labeledEdge = new LabeledEdge<>(DS_STORE, DS_SALES_FACT_1998, COL_STORE_ID);
	graph.addEdge(DS_STORE, DS_SALES_FACT_1998, labeledEdge);

	Map<String, Map<String, String>> datasetToAssociations = new HashMap<>();
	Map<String, String> associationToColumns = new HashMap<>();
	associationToColumns.put(COL_STORE_ID, COL_STORE_ID);
	datasetToAssociations.put(DS_STORE, associationToColumns);
	datasetToAssociations.put(DS_SALES_FACT_1998, associationToColumns);

	List<SimpleFilter> selections = new ArrayList<>(1);
	IDataSet dataSet = dataSetDAO.loadDataSetByLabel(DS_STORE);
	selections.add(new InFilter(new Projection(dataSet, "store_type"), Arrays.asList(new String[]{"Small Grocery"})));

	// realtimes means that they are not cached
	Set<String> realtimeDatasets = new HashSet<>();
	realtimeDatasets.add(DS_STORE);
	realtimeDatasets.add(DS_SALES_FACT_1998);

	Map<String, Map<String, String>> datasetParameters = new HashMap<>();
	HashMap<String, String> storeParameters = new HashMap<>();
	storeParameters.put("store_id", "100");
	datasetParameters.put(DS_STORE, storeParameters);

	Set<String> documents = new HashSet<>();

	Map<EdgeGroup, Set<Tuple>> edgeGroupToValues = null;

	Config config = AssociativeLogicUtils.buildConfig(AssociativeStrategyFactory.OUTER_STRATEGY, graph, datasetToAssociations, selections, realtimeDatasets,
			datasetParameters, documents);

	try {
		OuterAssociativityManager manager = new OuterAssociativityManager(config, UserProfileManager.getProfile());
		manager.process();
		edgeGroupToValues = manager.getResult().getEdgeGroupValues();
	} catch (Exception e) {
		e.printStackTrace();
		fail(e.toString());
	}

	assertNotNull(edgeGroupToValues);

	Set<LabeledEdge<String>> labeledEdges = new HashSet<>();
	labeledEdges.add(labeledEdge);
	// edge group is the collection if relations (associations) between 2 datasets
	EdgeGroup edgeGroup = new EdgeGroup(labeledEdges);
	assertTrue(edgeGroupToValues.containsKey(edgeGroup));

	Set<Tuple> values = edgeGroupToValues.get(edgeGroup);
	assertEquals(4, values.size());
	assertTrue(values.contains(new Tuple(Arrays.asList(new Integer[]{2}))));
	assertTrue(values.contains(new Tuple(Arrays.asList(new Integer[]{5}))));
	assertTrue(values.contains(new Tuple(Arrays.asList(new Integer[]{14}))));
	assertTrue(values.contains(new Tuple(Arrays.asList(new Integer[]{22}))));
}
 
Example 2
Source File: AssociativeLogicManagerTest.java    From Knowage-Server with GNU Affero General Public License v3.0 4 votes vote down vote up
@Test
public void testProcessThreeDatasetsTwoSimpleAssociations() {
	Pseudograph<String, LabeledEdge<String>> graph = new Pseudograph<>(
			new ClassBasedEdgeFactory<String, LabeledEdge<String>>((Class<LabeledEdge<String>>) (Object) LabeledEdge.class));
	graph.addVertex(DS_STORE);
	graph.addVertex(DS_SALES_FACT_1997);
	graph.addVertex(DS_PRODUCT);
	LabeledEdge<String> labeledEdgeStoreSales = new LabeledEdge<>(DS_STORE, DS_SALES_FACT_1997, COL_STORE_ID);
	graph.addEdge(DS_STORE, DS_SALES_FACT_1997, labeledEdgeStoreSales);
	LabeledEdge<String> labeledEdgeSalesProduct = new LabeledEdge<>(DS_SALES_FACT_1997, DS_PRODUCT, COL_PRODUCT_ID);
	graph.addEdge(DS_SALES_FACT_1997, DS_PRODUCT, labeledEdgeSalesProduct);

	Map<String, String> associationToColumnStore = new HashMap<>();
	associationToColumnStore.put(COL_STORE_ID, COL_STORE_ID);
	Map<String, String> associationToColumnProduct = new HashMap<>();
	associationToColumnProduct.put(COL_PRODUCT_ID, COL_PRODUCT_ID);
	Map<String, String> associationToColumnSales = new HashMap<>();
	associationToColumnSales.put(COL_STORE_ID, COL_STORE_ID);
	associationToColumnSales.put(COL_PRODUCT_ID, COL_PRODUCT_ID);
	Map<String, Map<String, String>> datasetToAssociations = new HashMap<>();
	datasetToAssociations.put(DS_STORE, associationToColumnStore);
	datasetToAssociations.put(DS_PRODUCT, associationToColumnProduct);
	datasetToAssociations.put(DS_SALES_FACT_1997, associationToColumnSales);

	List<SimpleFilter> selections = new ArrayList<>(1);
	IDataSet dataSet = dataSetDAO.loadDataSetByLabel(DS_PRODUCT);
	selections.add(new InFilter(new Projection(dataSet, "brand_name"), "Queen"));

	Set<String> realtimeDatasets = new HashSet<>();
	realtimeDatasets.add(DS_STORE);
	realtimeDatasets.add(DS_SALES_FACT_1997);
	realtimeDatasets.add(DS_PRODUCT);

	Map<String, Map<String, String>> datasetParameters = new HashMap<>();
	HashMap<String, String> storeParameters = new HashMap<>();
	storeParameters.put("store_id", "100");
	datasetParameters.put(DS_STORE, storeParameters);

	Set<String> documents = new HashSet<>();

	Map<EdgeGroup, Set<Tuple>> edgeGroupToValues = null;

	Config config = AssociativeLogicUtils.buildConfig(AssociativeStrategyFactory.OUTER_STRATEGY, graph, datasetToAssociations, selections, realtimeDatasets,
			datasetParameters, documents);

	try {
		OuterAssociativityManager manager = new OuterAssociativityManager(config, UserProfileManager.getProfile());
		manager.process();
		edgeGroupToValues = manager.getResult().getEdgeGroupValues();
	} catch (Exception e) {
		e.printStackTrace();
		fail(e.toString());
	}

	assertNotNull(edgeGroupToValues);
	assertEquals(2, edgeGroupToValues.size());

	Set<LabeledEdge<String>> labeledEdges = new HashSet<>();
	labeledEdges.add(labeledEdgeSalesProduct);
	EdgeGroup edgeGroup = new EdgeGroup(labeledEdges);
	assertTrue(edgeGroupToValues.containsKey(edgeGroup));

	Set<Tuple> values = edgeGroupToValues.get(edgeGroup);
	assertEquals(2, values.size());
	assertTrue(values.contains("('41')"));
	assertTrue(values.contains("('42')"));

	labeledEdges.clear();
	labeledEdges.add(labeledEdgeStoreSales);
	edgeGroup = new EdgeGroup(labeledEdges);
	assertTrue(edgeGroupToValues.containsKey(edgeGroup));

	values = edgeGroupToValues.get(edgeGroup);
	assertEquals(22, values.size());
	assertTrue(!values.contains("('0')"));
	assertTrue(!values.contains("('2')"));
	assertTrue(!values.contains("('22')"));
}
 
Example 3
Source File: AssociativeLogicManagerTest.java    From Knowage-Server with GNU Affero General Public License v3.0 4 votes vote down vote up
@Test
public void testProcessTwoDatasetsOneComplexAssociation() {
	Pseudograph<String, LabeledEdge<String>> graph = new Pseudograph<>(
			new ClassBasedEdgeFactory<String, LabeledEdge<String>>((Class<LabeledEdge<String>>) (Object) LabeledEdge.class));
	graph.addVertex(DS_STORE);
	graph.addVertex(DS_CUSTOMER);
	LabeledEdge<String> labeledEdgeStoreCustomer1 = new LabeledEdge<>(DS_STORE, DS_CUSTOMER, COL_CITY);
	graph.addEdge(DS_STORE, DS_CUSTOMER, labeledEdgeStoreCustomer1);
	LabeledEdge<String> labeledEdgeStoreCustomer2 = new LabeledEdge<>(DS_STORE, DS_CUSTOMER, COL_COUNTRY);
	graph.addEdge(DS_STORE, DS_CUSTOMER, labeledEdgeStoreCustomer2);

	Map<String, String> associationToColumnStore = new HashMap<>();
	associationToColumnStore.put(COL_CITY, COL_STORE_CITY);
	associationToColumnStore.put(COL_COUNTRY, COL_STORE_COUNTRY);
	Map<String, String> associationToColumnCustomer = new HashMap<>();
	associationToColumnCustomer.put(COL_CITY, COL_CITY);
	associationToColumnCustomer.put(COL_COUNTRY, COL_COUNTRY);
	Map<String, Map<String, String>> datasetToAssociations = new HashMap<>();
	datasetToAssociations.put(DS_STORE, associationToColumnStore);
	datasetToAssociations.put(DS_CUSTOMER, associationToColumnCustomer);

	List<SimpleFilter> selections = new ArrayList<>(1);
	IDataSet dataSet = dataSetDAO.loadDataSetByLabel(DS_CUSTOMER);
	selections.add(new InFilter(new Projection(dataSet, "gender"), "F"));

	Set<String> realtimeDatasets = new HashSet<>();
	Map<String, Map<String, String>> datasetParameters = new HashMap<>();
	Set<String> documents = new HashSet<>();

	Map<EdgeGroup, Set<Tuple>> edgeGroupToValues = null;

	Config config = AssociativeLogicUtils.buildConfig(AssociativeStrategyFactory.OUTER_STRATEGY, graph, datasetToAssociations, selections, realtimeDatasets,
			datasetParameters, documents);

	try {
		OuterAssociativityManager manager = new OuterAssociativityManager(config, UserProfileManager.getProfile());
		manager.process();
		edgeGroupToValues = manager.getResult().getEdgeGroupValues();
	} catch (Exception e) {
		e.printStackTrace();
		fail(e.toString());
	}

	assertNotNull(edgeGroupToValues);
	assertEquals(1, edgeGroupToValues.size());

	Set<LabeledEdge<String>> labeledEdges = new HashSet<>();
	labeledEdges.add(labeledEdgeStoreCustomer1);
	labeledEdges.add(labeledEdgeStoreCustomer2);
	EdgeGroup edgeGroup = new EdgeGroup(labeledEdges);
	assertTrue(edgeGroupToValues.containsKey(edgeGroup));

	Set<Tuple> values = edgeGroupToValues.get(edgeGroup);
	assertEquals(23, values.size());
}
 
Example 4
Source File: AssociativeLogicManagerTests.java    From Knowage-Server with GNU Affero General Public License v3.0 4 votes vote down vote up
@Test
public void testProcessTwoDatasetsOneSimpleAssociation() {
	Pseudograph<String, LabeledEdge<String>> graph = new Pseudograph<String, LabeledEdge<String>>(new ClassBasedEdgeFactory<String, LabeledEdge<String>>(
			(Class<LabeledEdge<String>>) (Object) LabeledEdge.class));
	graph.addVertex(DATASET_FOODMART_STORE);
	graph.addVertex(DATASET_FOODMART_CUSTOMER);
	LabeledEdge<String> labeledEdge = new LabeledEdge<String>(DATASET_FOODMART_STORE, DATASET_FOODMART_CUSTOMER, "A1");
	graph.addEdge(DATASET_FOODMART_STORE, DATASET_FOODMART_CUSTOMER, labeledEdge);

	Map<String, Map<String, String>> datasetToAssociations = new HashMap<String, Map<String, String>>();
	Map<String, String> associationToColumns = new HashMap<String, String>(1);
	associationToColumns.put("A1", COLUMN_STORE_CITY);
	datasetToAssociations.put(DATASET_FOODMART_STORE, associationToColumns);
	associationToColumns = new HashMap<String, String>(1);
	associationToColumns.put("A1", COLUMN_CITY);
	datasetToAssociations.put(DATASET_FOODMART_CUSTOMER, associationToColumns);

	Map<String, String> selections = new HashMap<String, String>(1);
	selections.put(DATASET_FOODMART_CUSTOMER, "customer_id = '4'");

	Set<String> realtimeDatasets = new HashSet<String>(0);
	Map<String, Map<String, String>> datasetParameters = new HashMap<String, Map<String, String>>();
	Set<String> documents = new HashSet<String>(0);

	Map<EdgeGroup, Set<String>> edgeGroupToValues = null;

	Config config = AssociativeLogicUtils.buildConfig(AssociativeStrategyFactory.OUTER_STRATEGY, graph, datasetToAssociations, selections,
			realtimeDatasets, datasetParameters, documents);
	try {
		OuterAssociativityManager manager = new OuterAssociativityManager(config, UserProfileManager.getProfile());
		edgeGroupToValues = manager.process().getEdgeGroupValues();
	} catch (Exception e) {
		e.printStackTrace();
		fail(e.toString());
	}

	assertNotNull(edgeGroupToValues);

	Set<LabeledEdge<String>> labeledEdges = new HashSet<LabeledEdge<String>>();
	labeledEdges.add(labeledEdge);
	EdgeGroup edgeGroup = new EdgeGroup(labeledEdges);
	assertTrue(edgeGroupToValues.containsKey(edgeGroup));

	Set<String> values = edgeGroupToValues.get(edgeGroup);
	assertEquals(1, values.size());
	assertTrue(values.contains("('Burnaby')"));
}
 
Example 5
Source File: AssociativeLogicManagerTests.java    From Knowage-Server with GNU Affero General Public License v3.0 4 votes vote down vote up
@Test
public void testProcessThreeDatasetsTwoSimpleAssociations() {
	Pseudograph<String, LabeledEdge<String>> graph = new Pseudograph<String, LabeledEdge<String>>(new ClassBasedEdgeFactory<String, LabeledEdge<String>>(
			(Class<LabeledEdge<String>>) (Object) LabeledEdge.class));
	graph.addVertex(DATASET_FOODMART_STORE);
	graph.addVertex(DATASET_FOODMART_CUSTOMER);
	graph.addVertex(DATASET_FOODMART_PRODUCT);
	LabeledEdge<String> labeledEdgeStoreCustomer = new LabeledEdge<String>(DATASET_FOODMART_STORE, DATASET_FOODMART_CUSTOMER, "A1");
	graph.addEdge(DATASET_FOODMART_STORE, DATASET_FOODMART_CUSTOMER, labeledEdgeStoreCustomer);
	LabeledEdge<String> labeledEdgeCustomerProduct = new LabeledEdge<String>(DATASET_FOODMART_CUSTOMER, DATASET_FOODMART_PRODUCT, "A2");
	graph.addEdge(DATASET_FOODMART_CUSTOMER, DATASET_FOODMART_PRODUCT, labeledEdgeCustomerProduct);

	Map<String, String> associationToColumnStore = new HashMap<String, String>();
	associationToColumnStore.put("A1", COLUMN_STORE_CITY);
	Map<String, String> associationToColumnProduct = new HashMap<String, String>();
	associationToColumnProduct.put("A2", COLUMN_PRODUCT_ID);
	Map<String, String> associationToColumnCustomer = new HashMap<String, String>();
	associationToColumnCustomer.put("A1", COLUMN_CITY);
	associationToColumnCustomer.put("A2", COLUMN_CUSTOMER_ID);
	Map<String, Map<String, String>> datasetToAssociations = new HashMap<String, Map<String, String>>();
	datasetToAssociations.put(DATASET_FOODMART_STORE, associationToColumnStore);
	datasetToAssociations.put(DATASET_FOODMART_PRODUCT, associationToColumnProduct);
	datasetToAssociations.put(DATASET_FOODMART_CUSTOMER, associationToColumnCustomer);

	Map<String, String> selections = new HashMap<String, String>();
	selections.put(DATASET_FOODMART_CUSTOMER, "account_num IN ('87500482201','17993524670')");

	Set<String> realtimeDatasets = new HashSet<String>();
	Map<String, Map<String, String>> datasetParameters = new HashMap<String, Map<String, String>>();
	Set<String> documents = new HashSet<String>();

	Map<EdgeGroup, Set<String>> edgeGroupToValues = null;

	Config config = AssociativeLogicUtils.buildConfig(AssociativeStrategyFactory.OUTER_STRATEGY, graph, datasetToAssociations, selections,
			realtimeDatasets, datasetParameters, documents);

	try {
		OuterAssociativityManager manager = new OuterAssociativityManager(config, UserProfileManager.getProfile());
		edgeGroupToValues = manager.process().getEdgeGroupValues();
	} catch (Exception e) {
		e.printStackTrace();
		fail(e.toString());
	}

	assertNotNull(edgeGroupToValues);
	assertEquals(2, edgeGroupToValues.size());

	Set<LabeledEdge<String>> labeledEdges = new HashSet<LabeledEdge<String>>();

	labeledEdges.add(labeledEdgeCustomerProduct);
	EdgeGroup edgeGroup = new EdgeGroup(labeledEdges);
	assertTrue(edgeGroupToValues.containsKey(edgeGroup));
	Set<String> values = edgeGroupToValues.get(edgeGroup);
	assertEquals(2, values.size());
	assertTrue(values.contains("('4')"));
	assertTrue(values.contains("('2163')"));
	labeledEdges.clear();

	labeledEdges.add(labeledEdgeStoreCustomer);
	edgeGroup = new EdgeGroup(labeledEdges);
	assertTrue(edgeGroupToValues.containsKey(edgeGroup));
	values = edgeGroupToValues.get(edgeGroup);
	assertTrue(values.contains("('Burnaby')"));
}
 
Example 6
Source File: AssociativeLogicManagerTests.java    From Knowage-Server with GNU Affero General Public License v3.0 4 votes vote down vote up
@Test
public void testProcessThreeDatasetsTwoSimpleAssociationsTwoSelections() {
	Pseudograph<String, LabeledEdge<String>> graph = new Pseudograph<String, LabeledEdge<String>>(new ClassBasedEdgeFactory<String, LabeledEdge<String>>(
			(Class<LabeledEdge<String>>) (Object) LabeledEdge.class));
	graph.addVertex(DATASET_FOODMART_STORE);
	graph.addVertex(DATASET_FOODMART_CUSTOMER);
	graph.addVertex(DATASET_FOODMART_PRODUCT);
	LabeledEdge<String> labeledEdgeStoreCustomer = new LabeledEdge<String>(DATASET_FOODMART_STORE, DATASET_FOODMART_CUSTOMER, "A1");
	graph.addEdge(DATASET_FOODMART_STORE, DATASET_FOODMART_CUSTOMER, labeledEdgeStoreCustomer);
	LabeledEdge<String> labeledEdgeCustomerProduct = new LabeledEdge<String>(DATASET_FOODMART_CUSTOMER, DATASET_FOODMART_PRODUCT, "A2");
	graph.addEdge(DATASET_FOODMART_CUSTOMER, DATASET_FOODMART_PRODUCT, labeledEdgeCustomerProduct);

	Map<String, String> associationToColumnStore = new HashMap<String, String>();
	associationToColumnStore.put("A1", COLUMN_STORE_CITY);
	Map<String, String> associationToColumnProduct = new HashMap<String, String>();
	associationToColumnProduct.put("A2", COLUMN_PRODUCT_ID);
	Map<String, String> associationToColumnCustomer = new HashMap<String, String>();
	associationToColumnCustomer.put("A1", COLUMN_CITY);
	associationToColumnCustomer.put("A2", COLUMN_CUSTOMER_ID);
	Map<String, Map<String, String>> datasetToAssociations = new HashMap<String, Map<String, String>>();
	datasetToAssociations.put(DATASET_FOODMART_STORE, associationToColumnStore);
	datasetToAssociations.put(DATASET_FOODMART_PRODUCT, associationToColumnProduct);
	datasetToAssociations.put(DATASET_FOODMART_CUSTOMER, associationToColumnCustomer);

	Map<String, String> selections = new LinkedHashMap<String, String>();
	selections.put(DATASET_FOODMART_CUSTOMER, "account_num IN ('87500482201','17993524670')");
	selections.put(DATASET_FOODMART_PRODUCT, "product_id = '4'");

	Set<String> realtimeDatasets = new HashSet<String>();
	Map<String, Map<String, String>> datasetParameters = new HashMap<String, Map<String, String>>();
	Set<String> documents = new HashSet<String>();

	Map<EdgeGroup, Set<String>> edgeGroupToValues = null;

	Config config = AssociativeLogicUtils.buildConfig(AssociativeStrategyFactory.OUTER_STRATEGY, graph, datasetToAssociations, selections,
			realtimeDatasets, datasetParameters, documents);

	try {
		OuterAssociativityManager manager = new OuterAssociativityManager(config, UserProfileManager.getProfile());
		edgeGroupToValues = manager.process().getEdgeGroupValues();
	} catch (Exception e) {
		e.printStackTrace();
		fail(e.toString());
	}

	assertNotNull(edgeGroupToValues);
	assertEquals(2, edgeGroupToValues.size());

	Set<LabeledEdge<String>> labeledEdges = new HashSet<LabeledEdge<String>>();

	labeledEdges.add(labeledEdgeCustomerProduct);
	EdgeGroup edgeGroup = new EdgeGroup(labeledEdges);
	assertTrue(edgeGroupToValues.containsKey(edgeGroup));
	Set<String> values = edgeGroupToValues.get(edgeGroup);
	assertEquals(1, values.size());
	assertTrue(values.contains("('4')"));
	assertTrue(!values.contains("('2163')"));
	labeledEdges.clear();

	labeledEdges.add(labeledEdgeStoreCustomer);
	edgeGroup = new EdgeGroup(labeledEdges);
	assertTrue(edgeGroupToValues.containsKey(edgeGroup));
	values = edgeGroupToValues.get(edgeGroup);
	assertTrue(values.contains("('Burnaby')"));
}
 
Example 7
Source File: AssociativeLogicManagerTests.java    From Knowage-Server with GNU Affero General Public License v3.0 4 votes vote down vote up
@Test
public void testProcessFourDatasetsThreeSimpleAssociations() {
	Pseudograph<String, LabeledEdge<String>> graph = new Pseudograph<String, LabeledEdge<String>>(new ClassBasedEdgeFactory<String, LabeledEdge<String>>(
			(Class<LabeledEdge<String>>) (Object) LabeledEdge.class));
	graph.addVertex(DATASET_FOODMART_STORE);
	graph.addVertex(DATASET_FOODMART_CUSTOMER);
	graph.addVertex(DATASET_FOODMART_PRODUCT);
	graph.addVertex(DATASET_FOODMART_PRODUCTCLASS);
	LabeledEdge<String> labeledEdgeStoreCustomer = new LabeledEdge<String>(DATASET_FOODMART_STORE, DATASET_FOODMART_CUSTOMER, "A1");
	graph.addEdge(DATASET_FOODMART_STORE, DATASET_FOODMART_CUSTOMER, labeledEdgeStoreCustomer);
	LabeledEdge<String> labeledEdgeCustomerProduct = new LabeledEdge<String>(DATASET_FOODMART_CUSTOMER, DATASET_FOODMART_PRODUCT, "A2");
	graph.addEdge(DATASET_FOODMART_CUSTOMER, DATASET_FOODMART_PRODUCT, labeledEdgeCustomerProduct);
	LabeledEdge<String> labeledEdgeProductProductClass = new LabeledEdge<String>(DATASET_FOODMART_PRODUCT, DATASET_FOODMART_PRODUCTCLASS, "A3");
	graph.addEdge(DATASET_FOODMART_PRODUCT, DATASET_FOODMART_PRODUCTCLASS, labeledEdgeProductProductClass);

	Map<String, String> associationToColumnStore = new HashMap<String, String>();
	associationToColumnStore.put("A1", COLUMN_STORE_CITY);
	Map<String, String> associationToColumnProductClass = new HashMap<String, String>();
	associationToColumnProductClass.put("A3", COLUMN_PRODUCT_CLASS_ID);
	Map<String, String> associationToColumnProduct = new HashMap<String, String>();
	associationToColumnProduct.put("A2", COLUMN_PRODUCT_ID);
	associationToColumnProduct.put("A3", COLUMN_PRODUCT_CLASS_ID);
	Map<String, String> associationToColumnCustomer = new HashMap<String, String>();
	associationToColumnCustomer.put("A1", COLUMN_CITY);
	associationToColumnCustomer.put("A2", COLUMN_CUSTOMER_ID);
	Map<String, Map<String, String>> datasetToAssociations = new HashMap<String, Map<String, String>>();
	datasetToAssociations.put(DATASET_FOODMART_STORE, associationToColumnStore);
	datasetToAssociations.put(DATASET_FOODMART_PRODUCT, associationToColumnProduct);
	datasetToAssociations.put(DATASET_FOODMART_CUSTOMER, associationToColumnCustomer);
	datasetToAssociations.put(DATASET_FOODMART_PRODUCTCLASS, associationToColumnProductClass);

	Map<String, String> selections = new HashMap<String, String>();
	selections.put(DATASET_FOODMART_CUSTOMER, "account_num = '17993524670'");

	Set<String> realtimeDatasets = new HashSet<String>();
	Map<String, Map<String, String>> datasetParameters = new HashMap<String, Map<String, String>>();
	Set<String> documents = new HashSet<String>();

	Map<EdgeGroup, Set<String>> edgeGroupToValues = null;

	Config config = AssociativeLogicUtils.buildConfig(AssociativeStrategyFactory.OUTER_STRATEGY, graph, datasetToAssociations, selections,
			realtimeDatasets, datasetParameters, documents);

	try {
		OuterAssociativityManager manager = new OuterAssociativityManager(config, UserProfileManager.getProfile());
		edgeGroupToValues = manager.process().getEdgeGroupValues();
	} catch (Exception e) {
		e.printStackTrace();
		fail(e.toString());
	}

	assertNotNull(edgeGroupToValues);
	assertEquals(3, edgeGroupToValues.size());

	Set<LabeledEdge<String>> labeledEdges = new HashSet<LabeledEdge<String>>();

	labeledEdges.add(labeledEdgeCustomerProduct);
	EdgeGroup edgeGroup = new EdgeGroup(labeledEdges);
	assertTrue(edgeGroupToValues.containsKey(edgeGroup));
	Set<String> values = edgeGroupToValues.get(edgeGroup);
	assertEquals(1, values.size());
	assertTrue(values.contains("('2163')"));
	labeledEdges.clear();

	labeledEdges.add(labeledEdgeProductProductClass);
	edgeGroup = new EdgeGroup(labeledEdges);
	assertTrue(edgeGroupToValues.containsKey(edgeGroup));
	values = edgeGroupToValues.get(edgeGroup);
	assertTrue(values.isEmpty());
	labeledEdges.clear();

	labeledEdges.add(labeledEdgeStoreCustomer);
	edgeGroup = new EdgeGroup(labeledEdges);
	assertTrue(edgeGroupToValues.containsKey(edgeGroup));
	values = edgeGroupToValues.get(edgeGroup);
	assertTrue(values.contains("('Burnaby')"));
	labeledEdges.clear();
}
 
Example 8
Source File: AssociativeLogicManagerTests.java    From Knowage-Server with GNU Affero General Public License v3.0 4 votes vote down vote up
@Test
public void testProcessTwoDatasetsOneComplexAssociation() {
	Pseudograph<String, LabeledEdge<String>> graph = new Pseudograph<String, LabeledEdge<String>>(new ClassBasedEdgeFactory<String, LabeledEdge<String>>(
			(Class<LabeledEdge<String>>) (Object) LabeledEdge.class));
	graph.addVertex(DATASET_FOODMART_STORE);
	graph.addVertex(DATASET_FOODMART_CUSTOMER);
	LabeledEdge<String> labeledEdgeStoreCustomer1 = new LabeledEdge<String>(DATASET_FOODMART_STORE, DATASET_FOODMART_CUSTOMER, "A1");
	graph.addEdge(DATASET_FOODMART_STORE, DATASET_FOODMART_CUSTOMER, labeledEdgeStoreCustomer1);
	LabeledEdge<String> labeledEdgeStoreCustomer2 = new LabeledEdge<String>(DATASET_FOODMART_STORE, DATASET_FOODMART_CUSTOMER, "A2");
	graph.addEdge(DATASET_FOODMART_STORE, DATASET_FOODMART_CUSTOMER, labeledEdgeStoreCustomer2);

	Map<String, String> associationToColumnStore = new HashMap<String, String>();
	associationToColumnStore.put("A1", COLUMN_STORE_COUNTRY);
	associationToColumnStore.put("A2", COLUMN_STORE_CITY);
	Map<String, String> associationToColumnCustomer = new HashMap<String, String>();
	associationToColumnCustomer.put("A1", COLUMN_COUNTRY);
	associationToColumnCustomer.put("A2", COLUMN_CITY);
	Map<String, Map<String, String>> datasetToAssociations = new HashMap<String, Map<String, String>>();
	datasetToAssociations.put(DATASET_FOODMART_STORE, associationToColumnStore);
	datasetToAssociations.put(DATASET_FOODMART_CUSTOMER, associationToColumnCustomer);

	Map<String, String> selections = new HashMap<String, String>();
	selections.put(DATASET_FOODMART_CUSTOMER, "gender = 'F'");

	Set<String> realtimeDatasets = new HashSet<String>();
	Map<String, Map<String, String>> datasetParameters = new HashMap<String, Map<String, String>>();
	Set<String> documents = new HashSet<String>();

	Map<EdgeGroup, Set<String>> edgeGroupToValues = null;

	Config config = AssociativeLogicUtils.buildConfig(AssociativeStrategyFactory.OUTER_STRATEGY, graph, datasetToAssociations, selections,
			realtimeDatasets, datasetParameters, documents);

	try {
		OuterAssociativityManager manager = new OuterAssociativityManager(config, UserProfileManager.getProfile());
		edgeGroupToValues = manager.process().getEdgeGroupValues();
	} catch (Exception e) {
		e.printStackTrace();
		fail(e.toString());
	}

	assertNotNull(edgeGroupToValues);
	assertEquals(1, edgeGroupToValues.size());

	Set<LabeledEdge<String>> labeledEdges = new HashSet<LabeledEdge<String>>();
	labeledEdges.add(labeledEdgeStoreCustomer1);
	labeledEdges.add(labeledEdgeStoreCustomer2);
	EdgeGroup edgeGroup = new EdgeGroup(labeledEdges);
	assertTrue(edgeGroupToValues.containsKey(edgeGroup));

	Set<String> values = edgeGroupToValues.get(edgeGroup);
	assertEquals(109, values.size());
}