Search in sources :

Example 1 with Attribute

use of org.talend.dataquality.matchmerge.Attribute in project tdq-studio-se by Talend.

the class BlockAndMatchManager method getBlockKey.

/**
 * get the block key of one record
 *
 * @param record
 * @return
 */
private String getBlockKey(RichRecord record) {
    Map<String, String> columnValueMap = new HashMap<String, String>();
    for (String columnName : colName2IndexMap.keySet()) {
        int index = Integer.parseInt(colName2IndexMap.get(columnName));
        columnValueMap.put(columnName, record.getAttributes().get(index).getValue());
    }
    String blockkey = blockKeyGenerator.getGenKey(blockKeyDefinition, columnValueMap);
    // add the block key into the record
    Attribute attribute = new Attribute(MatchAnalysisConstant.BLOCK_KEY, record.getAttributes().size());
    attribute.setValue(blockkey);
    record.getAttributes().add(attribute);
    return blockkey;
}
Also used : HashMap(java.util.HashMap) Attribute(org.talend.dataquality.matchmerge.Attribute)

Example 2 with Attribute

use of org.talend.dataquality.matchmerge.Attribute in project tdq-studio-se by Talend.

the class FileDelimitedReader method createRichRecord.

/**
 * DOC yyin Comment method "createRichRecord".
 *
 * @param analysedValues
 * @return
 */
private Record createRichRecord(String[] analysedValues) {
    ArrayList<Attribute> attributes = new ArrayList<Attribute>();
    for (int i = 0; i < analysedValues.length; i++) {
        Attribute attribute = new Attribute(analysedColumnName[i], i);
        String value = String.valueOf(analysedValues[i]);
        attribute.setValue(value);
        attributes.add(attribute);
    }
    return new RichRecord(attributes, String.valueOf(index++), 0, StringUtils.EMPTY);
}
Also used : RichRecord(org.talend.dataquality.record.linkage.grouping.swoosh.RichRecord) Attribute(org.talend.dataquality.matchmerge.Attribute) ArrayList(java.util.ArrayList)

Example 3 with Attribute

use of org.talend.dataquality.matchmerge.Attribute in project tdq-studio-se by Talend.

the class FileCSVReader method createRichRecord.

/**
 * DOC yyin Comment method "createRichRecord".
 *
 * @param analysedValues
 * @return
 */
private Record createRichRecord(String[] analysedValues) {
    ArrayList<Attribute> attributes = new ArrayList<Attribute>();
    for (int i = 0; i < analysedValues.length; i++) {
        Attribute attribute = new Attribute(analysedColumnName[i], i);
        String value = String.valueOf(analysedValues[i]);
        attribute.setValue(value);
        attributes.add(attribute);
    }
    return new RichRecord(attributes, String.valueOf(index++), 0, StringUtils.EMPTY);
}
Also used : RichRecord(org.talend.dataquality.record.linkage.grouping.swoosh.RichRecord) Attribute(org.talend.dataquality.matchmerge.Attribute) ArrayList(java.util.ArrayList)

Example 4 with Attribute

use of org.talend.dataquality.matchmerge.Attribute in project tdq-studio-se by Talend.

the class FileCSVReaderTest method testNext.

/**
 * Test method for {@link org.talend.cwm.db.connection.file.FileCSVReader#next()}.
 */
@Test
public void testNext() {
    try {
        File file = new File("./file.txt");
        if (file.exists()) {
            file.delete();
        }
        if (file.createNewFile()) {
            PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(file)));
            out.println("id,name,email");
            out.println("1,tom,a@b.cn");
            out.println("2,jerry,x@b.cn");
            out.println("3,bob,top@b.cn");
            out.close();
            DelimitedFileConnection delimitedFileconnection = ConnectionFactory.eINSTANCE.createDelimitedFileConnection();
            delimitedFileconnection.setFilePath(file.getAbsolutePath());
            delimitedFileconnection.setLimitValue("0");
            delimitedFileconnection.setHeaderValue("1");
            delimitedFileconnection.setFieldSeparatorValue(",");
            List<ModelElement> analysisElementList = new ArrayList<ModelElement>();
            MetadataTable table = ConnectionFactory.eINSTANCE.createMetadataTable();
            table.setName("table");
            MetadataColumn id = ConnectionFactory.eINSTANCE.createMetadataColumn();
            id.setName("id");
            id.setLabel("id");
            id.setTable(table);
            MetadataColumn name = ConnectionFactory.eINSTANCE.createMetadataColumn();
            name.setName("name");
            name.setLabel("name");
            name.setTable(table);
            MetadataColumn email = ConnectionFactory.eINSTANCE.createMetadataColumn();
            email.setName("email");
            email.setLabel("email");
            email.setTable(table);
            analysisElementList.add(id);
            analysisElementList.add(name);
            analysisElementList.add(email);
            FileCSVReader fileCSVReader = new FileCSVReader(file, delimitedFileconnection, analysisElementList);
            String fileContent = "";
            int i = 0;
            while (fileCSVReader.hasNext()) {
                i++;
                Record record = fileCSVReader.next();
                List<Attribute> attributes = record.getAttributes();
                fileContent += i + ":";
                for (Attribute attribute : attributes) {
                    fileContent += "[" + attribute.getLabel() + "," + attribute.getValue() + "]";
                }
            }
            fileCSVReader.close();
            Assert.assertEquals("1:[id,1][name,tom][email,a@b.cn]2:[id,2][name,jerry][email,x@b.cn]3:[id,3][name,bob][email,top@b.cn]", fileContent);
        }
        // delete the temp file
        if (file.exists()) {
            file.delete();
        }
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : Attribute(org.talend.dataquality.matchmerge.Attribute) FileWriter(java.io.FileWriter) ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) DelimitedFileConnection(org.talend.core.model.metadata.builder.connection.DelimitedFileConnection) IOException(java.io.IOException) BufferedWriter(java.io.BufferedWriter) ModelElement(orgomg.cwm.objectmodel.core.ModelElement) MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) Record(org.talend.dataquality.matchmerge.Record) File(java.io.File) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Aggregations

Attribute (org.talend.dataquality.matchmerge.Attribute)4 ArrayList (java.util.ArrayList)3 RichRecord (org.talend.dataquality.record.linkage.grouping.swoosh.RichRecord)2 BufferedWriter (java.io.BufferedWriter)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1 PrintWriter (java.io.PrintWriter)1 HashMap (java.util.HashMap)1 Test (org.junit.Test)1 DelimitedFileConnection (org.talend.core.model.metadata.builder.connection.DelimitedFileConnection)1 MetadataColumn (org.talend.core.model.metadata.builder.connection.MetadataColumn)1 MetadataTable (org.talend.core.model.metadata.builder.connection.MetadataTable)1 Record (org.talend.dataquality.matchmerge.Record)1 ModelElement (orgomg.cwm.objectmodel.core.ModelElement)1