Skip to content

Commit

Permalink
changes for izargs
Browse files Browse the repository at this point in the history
  • Loading branch information
sonalgoyal committed May 8, 2024
1 parent 781e9ae commit 6607b07
Show file tree
Hide file tree
Showing 34 changed files with 198 additions and 89 deletions.
38 changes: 19 additions & 19 deletions common/client/src/main/java/zingg/common/client/ArgumentsUtil.java
Expand Up @@ -19,7 +19,7 @@

public class ArgumentsUtil {

protected Class<? extends IZArgs<?>> argsClass;
protected Class<? extends IZArgs> argsClass;
private static final String ENV_VAR_MARKER_START = "$";
private static final String ENV_VAR_MARKER_END = "$";
private static final String ESC = "\\";
Expand All @@ -31,7 +31,7 @@ public ArgumentsUtil() {
this(Arguments.class);
}

public ArgumentsUtil( Class<? extends IZArgs<?>> argsClass) {
public ArgumentsUtil( Class<? extends IZArgs> argsClass) {
this.argsClass = argsClass;
}

Expand All @@ -44,7 +44,7 @@ public ArgumentsUtil( Class<? extends IZArgs<?>> argsClass) {
* @throws ZinggClientException
* in case of invalid/wrong json/file not found
*/
public IZArgs<?> createArgumentsFromJSON(String filePath)
public IZArgs createArgumentsFromJSON(String filePath)
throws ZinggClientException {
return createArgumentsFromJSON(filePath, "match");
}
Expand All @@ -58,7 +58,7 @@ public IZArgs<?> createArgumentsFromJSON(String filePath)
* @throws ZinggClientException
* in case of invlaid/wrong json/file not found
*/
public IZArgs<?> createArgumentsFromJSON(String filePath, String phase)
public IZArgs createArgumentsFromJSON(String filePath, String phase)
throws ZinggClientException {
try {
ObjectMapper mapper = new ObjectMapper();
Expand All @@ -69,7 +69,7 @@ public IZArgs<?> createArgumentsFromJSON(String filePath, String phase)
module.addDeserializer(List<MatchType>.class, new FieldDefinition.MatchTypeDeserializer());
mapper.registerModule(module);
*/
IZArgs<?> args = mapper.readValue(new File(filePath), argsClass);
IZArgs args = mapper.readValue(new File(filePath), argsClass);
LOG.warn("phase is " + phase);
//checkValid(args, phase);
return args;
Expand All @@ -89,7 +89,7 @@ public IZArgs<?> createArgumentsFromJSON(String filePath, String phase)
* @throws ZinggClientException
* in case there is an error in writing to file
*/
public void writeArgumentsToJSON(String filePath, IZArgs<?> args)
public void writeArgumentsToJSON(String filePath, IZArgs args)
throws ZinggClientException {
try {
ObjectMapper mapper = new ObjectMapper();
Expand All @@ -104,7 +104,7 @@ public void writeArgumentsToJSON(String filePath, IZArgs<?> args)
}

/*
public void checkValid(IZArgs<?> args, String phase) throws ZinggClientException {
public void checkValid(IZArgs args, String phase) throws ZinggClientException {
if (phase.equals("train") || phase.equals("match") || phase.equals("trainMatch") || phase.equals("link")) {
checkIsValid((IArguments) args);
}
Expand All @@ -117,13 +117,13 @@ else if (!phase.equalsIgnoreCase("WEB")){
}
*/

public IZArgs<?> createArgumentsFromJSONString(String data, String phase)
public IZArgs createArgumentsFromJSONString(String data, String phase)
throws ZinggClientException {
try {
ObjectMapper mapper = new ObjectMapper();
mapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_CONTROL_CHARS,
true);
IZArgs<?> args = mapper.readValue(data, argsClass);
IZArgs args = mapper.readValue(data, argsClass);
LOG.warn("phase is " + phase);
//checkValid(args, phase);
return args;
Expand All @@ -134,15 +134,15 @@ public IZArgs<?> createArgumentsFromJSONString(String data, String phase)
}
}

public IZArgs<?> createArgumentsFromJSONTemplate(String filePath, String phase)
public IZArgs createArgumentsFromJSONTemplate(String filePath, String phase)
throws ZinggClientException {
try {
LOG.warn("Config Argument is " + filePath);
byte[] encoded = Files.readAllBytes(Paths.get(filePath));
String template = new String(encoded, StandardCharsets.UTF_8);
Map<String, String> env = System.getenv();
String updatedJson = substituteVariables(template, env);
IZArgs<?> args = createArgumentsFromJSONString(updatedJson, phase);
IZArgs args = createArgumentsFromJSONString(updatedJson, phase);
return args;
} catch (Exception e) {
//e.printStackTrace();
Expand Down Expand Up @@ -176,7 +176,7 @@ public String substituteVariables(String template, Map<String, String> variables
return buffer.toString();
}

public void writeArgumentstoJSON(String filePath, IZArgs<?> args) throws ZinggClientException {
public void writeArgumentstoJSON(String filePath, IZArgs args) throws ZinggClientException {
try{
ObjectMapper mapper = new ObjectMapper();
mapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_CONTROL_CHARS,
Expand All @@ -190,7 +190,7 @@ public void writeArgumentstoJSON(String filePath, IZArgs<?> args) throws ZinggCl
}
}

public String writeArgumentstoJSONString(IZArgs<?> args) throws ZinggClientException {
public String writeArgumentstoJSONString(IZArgs args) throws ZinggClientException {
try{
ObjectMapper mapper = new ObjectMapper();
mapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_CONTROL_CHARS,
Expand All @@ -209,23 +209,23 @@ public String writeArgumentstoJSONString(IZArgs<?> args) throws ZinggClientExcep
* @param args
* @throws ZinggClientException
public void checkIsValid(IZArgs<?> args) throws ZinggClientException {
IZArgs<?> arg = new Arguments();
public void checkIsValid(IZArgs args) throws ZinggClientException {
IZArgs arg = new Arguments();
arg.setTrainingSamples(args.getTrainingSamples());
arg.setData(args.getData());
arg.setNumPartitions(args.getNumPartitions());
arg.setFieldDefinition(args.getFieldDefinition());
}
public void checkIsValidForOthers(IZArgs<?> args) throws ZinggClientException {
IZArgs<?> arg = new Arguments();
public void checkIsValidForOthers(IZArgs args) throws ZinggClientException {
IZArgs arg = new Arguments();
arg.setData(args.getData());
arg.setNumPartitions(args.getNumPartitions());
}
public void checkIsValidForLabelling(IZArgs<?> args) throws ZinggClientException {
IZArgs<?> arg = new Arguments();
public void checkIsValidForLabelling(IZArgs args) throws ZinggClientException {
IZArgs arg = new Arguments();
//arg.setPositiveTrainingSamples(args.getPositiveTrainingSamples());
//arg.setNegativeTrainingSamples(args.getNegativeTrainingSamples());
arg.setData(args.getData());
Expand Down
12 changes: 6 additions & 6 deletions common/client/src/main/java/zingg/common/client/Client.java
Expand Up @@ -25,9 +25,9 @@
*/
public abstract class Client<S,D,R,C,T> implements Serializable {
private static final long serialVersionUID = 1L;
protected IZArgs<?> arguments;
protected IZArgs arguments;
protected ArgumentsUtil argsUtil;
protected IZingg<S,D,R,C, ? extends IZArgs<?>> zingg;
protected IZingg<S,D,R,C> zingg;
protected ClientOptions options;
protected S session;
protected PipeUtilBase<S,D,R,C> pipeUtil;
Expand Down Expand Up @@ -103,11 +103,11 @@ public void setZingg(IZArgs args, ClientOptions options) throws Exception{
}


public void setZingg(IZingg<S,D,R,C, ? extends IZArgs<?>> zingg) {
public void setZingg(IZingg<S,D,R,C> zingg) {
this.zingg = zingg;
}

public void buildAndSetArguments(IZArgs<?> args, ClientOptions options) {
public void buildAndSetArguments(IZArgs args, ClientOptions options) {
setOptions(options);
int jobId = new Long(System.currentTimeMillis()).intValue();
if (options.get(options.JOBID)!= null) {
Expand Down Expand Up @@ -272,7 +272,7 @@ public void stop() throws ZinggClientException{
zingg.cleanup();
}

public IZArgs<?> getArguments() {
public IZArgs getArguments() {
return arguments;
}

Expand All @@ -285,7 +285,7 @@ public void postMetrics() throws ZinggClientException {
zingg.postMetrics();
}

public void setArguments(IZArgs<?> args) {
public void setArguments(IZArgs args) {
this.arguments = args;
}

Expand Down
Expand Up @@ -4,7 +4,7 @@

import zingg.common.client.pipe.Pipe;

public interface IArguments extends IZArgs<IArguments>{
public interface IArguments extends IZArgs{

void setThreshold(double threshold);

Expand Down
Expand Up @@ -3,7 +3,7 @@
/**
* Marker interface for all Zingg
*/
public interface IZArgs<A> {
public interface IZArgs {

boolean getCollectMetrics();

Expand Down
8 changes: 6 additions & 2 deletions common/client/src/main/java/zingg/common/client/IZingg.java
@@ -1,8 +1,8 @@
package zingg.common.client;

public interface IZingg<S,D,R,C, A extends IZArgs<A>> {
public interface IZingg<S,D,R,C> {

public void init(A args, S session)
public void init(IZArgs args, S session)
throws ZinggClientException;

public void execute() throws ZinggClientException;
Expand All @@ -21,6 +21,10 @@ public void init(A args, S session)
public ClientOptions getClientOptions();

public void setSession(S session);

public IZArgs getArgs();

public void setArgs(IZArgs a);


}
Expand Up @@ -4,6 +4,7 @@
import org.apache.commons.logging.LogFactory;

import zingg.common.client.IArguments;
import zingg.common.client.IZArgs;
import zingg.common.client.ZFrame;
import zingg.common.client.ZinggClientException;
import zingg.common.core.context.Context;
Expand All @@ -12,7 +13,7 @@ public abstract class DataColDocumenter<S,D,R,C,T> extends DocumenterBase<S,D,R,
protected static String name = "zingg.DataColDocumenter";
public static final Log LOG = LogFactory.getLog(DataColDocumenter.class);

public DataColDocumenter(Context<S,D,R,C,T> context, IArguments args) {
public DataColDocumenter(Context<S,D,R,C,T> context, IZArgs args) {
super(context, args);
}

Expand Down
Expand Up @@ -10,6 +10,7 @@

import zingg.common.client.FieldData;
import zingg.common.client.IArguments;
import zingg.common.client.IZArgs;
import zingg.common.client.ZFrame;
import zingg.common.client.ZinggClientException;
import zingg.common.core.context.Context;
Expand All @@ -22,7 +23,7 @@ public abstract class DataDocumenter<S,D,R,C,T> extends DocumenterBase<S,D,R,C,T
public static final Log LOG = LogFactory.getLog(DataDocumenter.class);
protected ZFrame<D,R,C> data;

public DataDocumenter(Context<S,D,R,C,T> context, IArguments args) {
public DataDocumenter(Context<S,D,R,C,T> context, IZArgs args) {
super(context, args);
data = getDSUtil().emptyDataFrame();
}
Expand Down
Expand Up @@ -10,6 +10,7 @@
import freemarker.template.TemplateExceptionHandler;
import freemarker.template.Version;
import zingg.common.client.IArguments;
import zingg.common.client.IZArgs;
import zingg.common.client.ZinggClientException;
import zingg.common.client.util.ColName;
import zingg.common.core.context.Context;
Expand All @@ -20,9 +21,9 @@ public abstract class DocumenterBase<S,D,R,C,T> extends ZinggBase<S,D,R,C,T>{
private static final long serialVersionUID = 1L;
protected static Configuration config;

public DocumenterBase(Context<S,D,R,C,T> context, IArguments args) {
public DocumenterBase(Context<S,D,R,C,T> context, IZArgs args) {
super.context = context;
super.args = args;
super.args = (IArguments) args;
config = createConfigurationObject();
}

Expand Down
Expand Up @@ -7,6 +7,8 @@
import org.apache.commons.logging.LogFactory;

import zingg.common.client.IArguments;
import zingg.common.client.IZArgs;

import zingg.common.client.ZFrame;
import zingg.common.client.ZinggClientException;
import zingg.common.core.context.Context;
Expand All @@ -18,7 +20,7 @@ public abstract class ModelColDocumenter<S,D,R,C,T> extends DocumenterBase<S,D,R
private final String COLUMN_DOC_TEMPLATE = "columnDocTemplate.ftlh";
private final String Z_COLUMN_TEMPLATE = "zColumnTemplate.ftlh";

public ModelColDocumenter(Context<S,D,R,C,T> context, IArguments args) {
public ModelColDocumenter(Context<S,D,R,C,T> context, IZArgs args) {
super(context, args);
}

Expand Down
Expand Up @@ -13,6 +13,7 @@
import zingg.common.client.FieldDefUtil;
import zingg.common.client.FieldDefinition;
import zingg.common.client.IArguments;
import zingg.common.client.IZArgs;
import zingg.common.client.ZFrame;
import zingg.common.client.ZinggClientException;
import zingg.common.client.util.ColName;
Expand All @@ -35,7 +36,7 @@ public abstract class ModelDocumenter<S,D,R,C,T> extends DocumenterBase<S,D,R,C,

protected FieldDefUtil fieldDefUtil;

public ModelDocumenter(Context<S,D,R,C,T> context, IArguments args) {
public ModelDocumenter(Context<S,D,R,C,T> context, IZArgs args) {
super(context, args);
markedRecords = getDSUtil().emptyDataFrame();
fieldDefUtil = new FieldDefUtil();
Expand Down
Expand Up @@ -4,6 +4,7 @@
import org.apache.commons.logging.LogFactory;

import zingg.common.client.IArguments;
import zingg.common.client.IZArgs;
import zingg.common.client.ZinggClientException;
import zingg.common.client.options.ZinggOptions;

Expand All @@ -20,7 +21,7 @@ public FindAndLabeller() {
}

@Override
public void init(IArguments args, S s) throws ZinggClientException {
public void init(IZArgs args, S s) throws ZinggClientException {
finder.init(args,s);
labeller.init(args,s);
super.init(args,s);
Expand Down
Expand Up @@ -120,7 +120,7 @@ public void execute() throws ZinggClientException {
throw new UnsupportedOperationException();
}

@Override

public ILabelDataViewHelper<S, D, R, C> getLabelDataViewHelper() throws UnsupportedOperationException {
return this;
}
Expand Down
Expand Up @@ -158,7 +158,6 @@ int readCliInput() {
return selection;
}

@Override
public ITrainingDataModel<S, D, R, C> getTrainingDataModel() {
if (trainingDataModel==null) {
this.trainingDataModel = new TrainingDataModel<S, D, R, C, T>(getContext(), getClientOptions());
Expand All @@ -170,7 +169,7 @@ public void setTrainingDataModel(ITrainingDataModel<S, D, R, C> trainingDataMode
this.trainingDataModel = trainingDataModel;
}

@Override

public ILabelDataViewHelper<S, D, R, C> getLabelDataViewHelper() {
if(labelDataViewHelper==null) {
labelDataViewHelper = new LabelDataViewHelper<S,D,R,C,T>(getContext(), getClientOptions());
Expand Down
Expand Up @@ -4,6 +4,7 @@
import org.apache.commons.logging.LogFactory;

import zingg.common.client.IArguments;
import zingg.common.client.IZArgs;
import zingg.common.client.ZinggClientException;
import zingg.common.client.options.ZinggOptions;

Expand All @@ -21,7 +22,7 @@ public TrainMatcher() {
}

@Override
public void init(IArguments args, S s)
public void init(IZArgs args, S s)
throws ZinggClientException {
trainer.init(args,s);
matcher.init(args,s);
Expand Down
Expand Up @@ -17,7 +17,7 @@
import zingg.common.core.model.Model;
import zingg.common.core.preprocess.StopWordsRemover;

public abstract class TrainingDataFinder<S,D,R,C,T> extends ZinggBaseCommon<S,D,R,C,T>{
public abstract class TrainingDataFinder<S,D,R,C,T> extends ZinggBase<S,D,R,C,T>{

private static final long serialVersionUID = 1L;
protected static String name = "zingg.TrainingDataFinder";
Expand Down

0 comments on commit 6607b07

Please sign in to comment.