001/**
002 * Copyright (C) 2014  Universidade de Aveiro, DETI/IEETA, Bioinformatics Group - http://bioinformatics.ua.pt/
003 *
004 * This file is part of Dicoogle/dicoogle.
005 *
006 * Dicoogle/dicoogle is free software: you can redistribute it and/or modify
007 * it under the terms of the GNU General Public License as published by
008 * the Free Software Foundation, either version 3 of the License, or
009 * (at your option) any later version.
010 *
011 * Dicoogle/dicoogle is distributed in the hope that it will be useful,
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
014 * GNU General Public License for more details.
015 *
016 * You should have received a copy of the GNU General Public License
017 * along with Dicoogle.  If not, see <http://www.gnu.org/licenses/>.
018 */
019package pt.ua.dicoogle.core.dicom;
020
021import java.io.FileInputStream;
022import java.io.FileNotFoundException;
023import java.util.Scanner;
024import org.slf4j.Logger;
025import org.slf4j.LoggerFactory;
026import org.slf4j.Logger;
027import org.slf4j.LoggerFactory;
028
029import pt.ua.dicoogle.sdk.utils.TagValue;
030import pt.ua.dicoogle.sdk.utils.TagsStruct;
031
032/**
033 *
034 * @author bastiao
035 */
036public class PrivateDictionary 
037{
038
039    public void parse(String file)
040    {
041        String NL = System.getProperty("line.separator");
042        Scanner scanner = null;
043        try {
044            scanner = new Scanner(new FileInputStream(file));
045        } catch (FileNotFoundException ex) {
046            LoggerFactory.getLogger(PrivateDictionary.class).error(ex.getMessage(), ex);
047        }
048        try {
049            while (scanner.hasNextLine()) {
050                String text = scanner.nextLine();
051                String tag = ""; 
052                    
053                String type = "";
054                String name = ""; 
055                
056                
057                if (text.startsWith("(") )
058                {
059                    String txt[] = text.split(" |\t");
060
061                    for (int i = 0; i< txt.length; i++)
062                    {
063                        if (txt[i].startsWith("("))
064                        {
065                            tag = txt[i] ;
066                        }
067                        else if (txt[i].length()==2)
068                        {
069                            type = txt[i] ;
070                            name = txt[i+1] ;
071                        }
072                    }
073                }
074                if (!tag.equals("")&&!type.equals("")&&!name.equals(""))
075                {
076                    //System.out.println("Tag: "+tag);
077                    //System.out.println("Type: "+type);
078                    //System.out.println("Name: "+name);
079                    
080                    TagsStruct tg = TagsStruct.getInstance();
081                    tag = tag.replaceAll("\\(", "");
082                    tag = tag.replaceAll("\\)", "");
083                    tag = tag.replaceAll(" ", "");
084                    tag = tag.replaceAll(",", "");
085                    //System.out.println("Tag: "+tag);
086                    //System.out.println("Type: "+type);
087                    //System.out.println("Name: "+name);
088                    
089                    TagValue v = new TagValue(Integer.parseInt(tag, 16), name);
090                    
091                    v.setVR(type);
092                    tg.addPrivateField(v);
093                    
094                }
095            }
096        } finally {
097            scanner.close();
098        }
099    }
100    
101    public static void main(String [] args)
102    {
103        PrivateDictionary pd = new PrivateDictionary();
104        pd.parse("/Users/bastiao/MAP-I/Code/dicomlamedictionaryanddicom/similarity.dic");
105        
106    
107    }
108    
109}