source: trunk/autoquest-plugin-genericevents/src/main/java/de/ugoe/cs/autoquest/plugin/genericevents/commands/CMDparseSogouQDataFile.java @ 2153

Last change on this file since 2153 was 2153, checked in by pharms, 7 years ago
  • Property svn:mime-type set to text/plain
File size: 4.0 KB
Line 
1//   Copyright 2015 Georg-August-Universität Göttingen, Germany
2//
3//   Licensed under the Apache License, Version 2.0 (the "License");
4//   you may not use this file except in compliance with the License.
5//   You may obtain a copy of the License at
6//
7//       http://www.apache.org/licenses/LICENSE-2.0
8//
9//   Unless required by applicable law or agreed to in writing, software
10//   distributed under the License is distributed on an "AS IS" BASIS,
11//   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12//   See the License for the specific language governing permissions and
13//   limitations under the License.
14
15package de.ugoe.cs.autoquest.plugin.genericevents.commands;
16
17import java.io.File;
18import java.util.ArrayList;
19import java.util.Collection;
20import java.util.List;
21import java.util.Map;
22
23import de.ugoe.cs.autoquest.CommandHelpers;
24import de.ugoe.cs.autoquest.eventcore.Event;
25import de.ugoe.cs.util.console.Command;
26import de.ugoe.cs.util.console.Console;
27import de.ugoe.cs.util.console.GlobalDataContainer;
28
29/**
30 * <p>
31 * TODO comment
32 * </p>
33 *
34 * @author Patrick Harms
35 */
36public class CMDparseSogouQDataFile implements Command {
37
38    /* (non-Javadoc)
39     * @see de.ugoe.cs.util.console.Command#run(java.util.List)
40     */
41    @Override
42    public void run(List<Object> parameters) {
43        String path = null;
44        String sequencesName = null;
45        boolean hasTimestamp = false;
46        boolean ignoreQuery = false;
47        boolean compareDomainOnly = false;
48       
49        try {
50            for (int i = 0; i < parameters.size(); i++) {
51                String parameter = (String) parameters.get(i);
52                if (!parameter.startsWith("-")) {
53                    if (path == null) {
54                        path = parameter;
55                    }
56                    else if (sequencesName == null) {
57                        sequencesName = parameter;
58                    }
59                    else {
60                        throw new IllegalArgumentException("unrecognized parameter: " + parameter);
61                    }
62                }
63                else {
64                    if ("-hasTimestamp".equals(parameter)) {
65                        hasTimestamp = true;
66                    }
67                    else if ("-ignoreQuery".equals(parameter)) {
68                        ignoreQuery = true;
69                    }
70                    else if ("-compareDomainOnly".equals(parameter)) {
71                        compareDomainOnly = true;
72                    }
73                    else {
74                        throw new IllegalArgumentException("unrecognized parameter: " + parameter);
75                    }
76                }
77            }
78        }
79        catch (IllegalArgumentException e) {
80            throw e;
81        }
82        catch (Exception e) {
83            throw new IllegalArgumentException("could not process parameters", e);
84        }
85       
86        if (path == null) {
87            throw new IllegalArgumentException("no path to file provided");
88        }
89       
90        if (sequencesName == null) {
91            sequencesName = "sequences";
92        }
93
94        File file = new File(path);
95        if (file.isDirectory()) {
96            Console.printerrln(path + " is not a file but a directory");
97            return;
98        }
99       
100        Map<String, List<Event>> userSessions = new SogouQDataFileParser().parseFile
101            (file, hasTimestamp, ignoreQuery, compareDomainOnly);
102       
103        Collection<List<Event>> sequences = new ArrayList<>();
104       
105        for (List<Event> session : userSessions.values()) {
106            if (session.size() > 1) {
107                sequences.add(session);
108            }
109        }
110
111        if (GlobalDataContainer.getInstance().addData(sequencesName, sequences)) {
112            CommandHelpers.dataOverwritten(sequencesName);
113        }
114    }
115
116    /* (non-Javadoc)
117     * @see de.ugoe.cs.util.console.Command#help()
118     */
119    @Override
120    public String help() {
121        return "parseSogouQDataFile <file> {<sequencesName>} {-hasTimestamp} {-ignoreQuery} " +
122            "{-compareDomainOnly}";
123    }
124
125}
Note: See TracBrowser for help on using the repository browser.