text:
@inproceedings{10.5555/2391200.2391201,
author = {Niepert, Mathias and Meilicke, Christian and Stuckenschmidt, Heiner},
title = {Towards Distributed MCMC Inference in Probabilistic Knowledge Bases},
year = {2012},
publisher = {Association for Computational Linguistics},
address = {USA},
abstract = {Probabilistic knowledge bases are commonly used in areas such as large-scale information extraction, data integration, and knowledge capture, to name but a few. Inference in probabilistic knowledge bases is a computationally challenging problem. With this contribution, we present our vision of a distributed inference algorithm based on conflict graph construction and hypergraph sampling. Early empirical results show that the approach efficiently and accurately computes a-posteriori probabilities of a knowledge base derived from a well-known information extraction system.},
booktitle = {Proceedings of the Joint Workshop on Automatic Knowledge Base Construction and Web-Scale Knowledge Extraction},
pages = {1–6},
numpages = {6},
location = {Montreal, Canada},
series = {AKBC-WEKEX '12}
}

@inproceedings{10.5555/2391200.2391202,
author = {Dalvi, Bhavana and Cohen, William W. and Callan, Jamie},
title = {Collectively Representing Semi-Structured Data from the Web},
year = {2012},
publisher = {Association for Computational Linguistics},
address = {USA},
abstract = {In this paper, we propose a single low-dimensional representation of a large collection of table and hyponym data, and show that with a small number of primitive operations, this representation can be used effectively for many purposes. Specifically we consider queries like set expansion, class prediction etc. We evaluate our methods on publicly available semi-structured datasets from the Web.},
booktitle = {Proceedings of the Joint Workshop on Automatic Knowledge Base Construction and Web-Scale Knowledge Extraction},
pages = {7–12},
numpages = {6},
location = {Montreal, Canada},
series = {AKBC-WEKEX '12}
}

@inproceedings{10.5555/2391200.2391203,
author = {Saggion, Horacio},
title = {Unsupervised Content Discovery from Concise Summaries},
year = {2012},
publisher = {Association for Computational Linguistics},
address = {USA},
abstract = {Domain adaptation is a time consuming and costly procedure calling for the development of algorithms and tools to facilitate its automation. This paper presents an unsupervised algorithm able to learn the main concepts in event summaries. The method takes as input a set of domain summaries annotated with shallow linguistic information and produces a domain template. We demonstrate the viability of the method by applying it to three different domains and two languages. We have evaluated the generated templates against human templates obtaining encouraging results.},
booktitle = {Proceedings of the Joint Workshop on Automatic Knowledge Base Construction and Web-Scale Knowledge Extraction},
pages = {13–18},
numpages = {6},
location = {Montreal, Canada},
series = {AKBC-WEKEX '12}
}

@inproceedings{10.5555/2391200.2391204,
author = {Bronzi, Mirko and Guo, Zhaochen and Mesquita, Filipe and Barbosa, Denilson and Merialdo, Paolo},
title = {Automatic Evaluation of Relation Extraction Systems on Large-Scale},
year = {2012},
publisher = {Association for Computational Linguistics},
address = {USA},
abstract = {The extraction of relations between named entities from natural language text is a longstanding challenge in information extraction, especially in large-scale. A major challenge for the advancement of this research field has been the lack of meaningful evaluation frameworks based on realistic-sized corpora. In this paper we propose a framework for large-scale evaluation of relation extraction systems based on an automatic annotator that uses a public online database and a large web corpus.},
booktitle = {Proceedings of the Joint Workshop on Automatic Knowledge Base Construction and Web-Scale Knowledge Extraction},
pages = {19–24},
numpages = {6},
location = {Montreal, Canada},
series = {AKBC-WEKEX '12}
}

@inproceedings{10.5555/2391200.2391205,
author = {Tamang, Suzanne and Ji, Heng},
title = {Relabeling Distantly Supervised Training Data for Temporal Knowledge Base Population},
year = {2012},
publisher = {Association for Computational Linguistics},
address = {USA},
abstract = {We enhance a temporal knowledge base population system to improve the quality of distantly supervised training data and identify a minimal feature set for classification. The approach uses multi-class logistic regression to eliminate individual features based on the strength of their association with a temporal label followed by semi-supervised relabeling using a subset of human annotations and lasso regression. As implemented in this work, our technique improves performance and results in notably less computational cost than a parallel system trained on the full feature set.},
booktitle = {Proceedings of the Joint Workshop on Automatic Knowledge Base Construction and Web-Scale Knowledge Extraction},
pages = {25–30},
numpages = {6},
location = {Montreal, Canada},
series = {AKBC-WEKEX '12}
}

@inproceedings{10.5555/2391200.2391206,
author = {Li, Bin and Chen, Jiajun and Zhang, Yingjie},
title = {Web Based Collection and Comparison of Cognitive Properties in English and Chinese},
year = {2012},
publisher = {Association for Computational Linguistics},
address = {USA},
abstract = {Cognitive properties of words are very useful in figurative language understanding, language acquisition and translation. To overcome the subjectivity and low efficiency in manual construction of such database, we propose a web-based method for automatic collection and analysis of cognitive properties. The method employs simile templates to query the search engines. With the help of a bilingual dictionary, the method is able to collect tens of thousands of "vehicle-adjective" items of high quality. Frequencies are then used to obtain the common and independent cognitive properties automatically. The method can be extended conveniently to other languages to construct multi-lingual cognitive property knowledgebase.},
booktitle = {Proceedings of the Joint Workshop on Automatic Knowledge Base Construction and Web-Scale Knowledge Extraction},
pages = {31–34},
numpages = {4},
location = {Montreal, Canada},
series = {AKBC-WEKEX '12}
}

@inproceedings{10.5555/2391200.2391207,
author = {Stern, Rosa and Sagot, Beno\^{\i}t},
title = {Population of a Knowledge Base for News Metadata from Unstructured Text and Web Data},
year = {2012},
publisher = {Association for Computational Linguistics},
address = {USA},
abstract = {We present a practical use case of knowledge base (KB) population at the French news agency AFP. The target KB instances are entities relevant for news production and content enrichment. In order to acquire uniquely identified entities over news wires, i.e. textual data, and integrate the resulting KB in the Linked Data framework, a series of data models need to be aligned: Web data resources are harvested for creating a wide coverage entity database, which is in turn used to link entities to their mentions in French news wires. Finally, the extracted entities are selected for instantiation in the target KB. We describe our methodology along with the resources created and used for the target KB population.},
booktitle = {Proceedings of the Joint Workshop on Automatic Knowledge Base Construction and Web-Scale Knowledge Extraction},
pages = {35–40},
numpages = {6},
location = {Montreal, Canada},
series = {AKBC-WEKEX '12}
}

@inproceedings{10.5555/2391200.2391208,
author = {Nakashole, Ndapandula and Weikum, Gerhard},
title = {Real-Time Population of Knowledge Bases: Opportunities and Challenges},
year = {2012},
publisher = {Association for Computational Linguistics},
address = {USA},
abstract = {Dynamic content is a frequently accessed part of the Web. However, most information extraction approaches are batch-oriented, thus not effective for gathering rapidly changing data. This paper proposes a model for fact extraction in real-time. Our model addresses the difficult challenges that timely fact extraction on frequently updated data entails. We point out a naive solution to the main research question and justify the choices we make in the model we propose.},
booktitle = {Proceedings of the Joint Workshop on Automatic Knowledge Base Construction and Web-Scale Knowledge Extraction},
pages = {41–45},
numpages = {5},
location = {Montreal, Canada},
series = {AKBC-WEKEX '12}
}

@inproceedings{10.5555/2391200.2391209,
author = {Gardner, Matthew},
title = {Adding Distributional Semantics to Knowledge Base Entities through Web-Scale Entity Linking},
year = {2012},
publisher = {Association for Computational Linguistics},
address = {USA},
abstract = {Web-scale knowledge bases typically consist entirely of predicates over entities. However, the distributional properties of how those entities appear in text are equally important aspects of knowledge. If noun phrases mapped unambiguously to knowledge base entities, adding this knowledge would simply require counting. The many-to-many relationship between noun phrase mentions and knowledge base entities makes adding distributional knowledge about entities difficult. In this paper, we argue that this information should be explicitly included in web-scale knowledge bases. We propose a generative model that learns these distributional semantics by performing entity linking on the web, and we give some preliminary results that point to its usefulness.},
booktitle = {Proceedings of the Joint Workshop on Automatic Knowledge Base Construction and Web-Scale Knowledge Extraction},
pages = {46–51},
numpages = {6},
location = {Montreal, Canada},
series = {AKBC-WEKEX '12}
}

@inproceedings{10.5555/2391200.2391210,
author = {Akbik, Alan and L\"{o}ser, Alexander},
title = {KrakeN: N-Ary Facts in Open Information Extraction},
year = {2012},
publisher = {Association for Computational Linguistics},
address = {USA},
abstract = {Current techniques for Open Information Extraction (OIE) focus on the extraction of binary facts and suffer significant quality loss for the task of extracting higher order N-ary facts. This quality loss may not only affect the correctness, but also the completeness of an extracted fact. We present KrakeN, an OIE system specifically designed to capture N-ary facts, as well as the results of an experimental study on extracting facts from Web text in which we examine the issue of fact completeness. Our preliminary experiments indicate that KrakeN is a high precision OIE approach that captures more facts per sentence at greater completeness than existing OIE approaches, but is vulnerable to noisy and ungrammatical text.},
booktitle = {Proceedings of the Joint Workshop on Automatic Knowledge Base Construction and Web-Scale Knowledge Extraction},
pages = {52–56},
numpages = {5},
location = {Montreal, Canada},
series = {AKBC-WEKEX '12}
}

@inproceedings{10.5555/2391200.2391211,
author = {Grishman, Ralph},
title = {Structural Linguistics and Unsupervised Information Extraction},
year = {2012},
publisher = {Association for Computational Linguistics},
address = {USA},
abstract = {A precondition for extracting information from large text corpora is discovering the information structures underlying the text. Progress in this direction is being made in the form of unsupervised information extraction (IE). We describe recent work in unsupervised relation extraction and compare its goals to those of grammar discovery for science sublanguages. We consider what this work on grammar discovery suggests for future directions in unsupervised IE.},
booktitle = {Proceedings of the Joint Workshop on Automatic Knowledge Base Construction and Web-Scale Knowledge Extraction},
pages = {57–61},
numpages = {5},
location = {Montreal, Canada},
series = {AKBC-WEKEX '12}
}

@inproceedings{10.5555/2391200.2391212,
author = {Stoyanov, Veselin and Mayfield, James and Xu, Tan and Oard, Douglas W. and Lawrie, Dawn and Oates, Tim and Finin, Tim},
title = {A Context-Aware Approach to Entity Linking},
year = {2012},
publisher = {Association for Computational Linguistics},
address = {USA},
abstract = {Entity linking refers to the task of assigning mentions in documents to their corresponding knowledge base entities. Entity linking is a central step in knowledge base population. Current entity linking systems do not explicitly model the discourse context in which the communication occurs. Nevertheless, the notion of shared context is central to the linguistic theory of pragmatics and plays a crucial role in Grice's cooperative communication principle. Furthermore, modeling context facilitates joint resolution of entities, an important problem in entity linking yet to be addressed satisfactorily. This paper describes an approach to context-aware entity linking.},
booktitle = {Proceedings of the Joint Workshop on Automatic Knowledge Base Construction and Web-Scale Knowledge Extraction},
pages = {62–67},
numpages = {6},
location = {Montreal, Canada},
series = {AKBC-WEKEX '12}
}

@inproceedings{10.5555/2391200.2391213,
author = {Mayfield, James and Finin, Tim},
title = {Evaluating the Quality of a Knowledge Base Populated from Text},
year = {2012},
publisher = {Association for Computational Linguistics},
address = {USA},
abstract = {The steady progress of information extraction systems has been helped by sound methodologies for evaluating their performance in controlled experiments. Annual events like MUC, ACE and TAC have developed evaluation approaches enabling researchers to score and rank their systems relative to reference results. Yet these evaluations have only assessed component technologies needed by a knowledge base population system; none has required the construction of a knowledge base that is then evaluated directly. We describe an approach to the direct evaluation of a knowledge base and an instantiation that will be used in a 2012 TAC Knowledge Base Population track.},
booktitle = {Proceedings of the Joint Workshop on Automatic Knowledge Base Construction and Web-Scale Knowledge Extraction},
pages = {68–73},
numpages = {6},
location = {Montreal, Canada},
series = {AKBC-WEKEX '12}
}

@inproceedings{10.5555/2391200.2391214,
author = {Clark, Peter and Harrison, Phil and Balasubramanian, Niranjan and Etzioni, Oren},
title = {Constructing a Textual KB from a Biology TextBook},
year = {2012},
publisher = {Association for Computational Linguistics},
address = {USA},
abstract = {As part of our work on building a "knowledgeable textbook" about biology, we are developing a textual question-answering (QA) system that can answer certain classes of biology questions posed by users. In support of that, we are building a "textual KB" - an assembled set of semi-structured assertions based on the book - that can be used to answer users' queries, can be improved using global consistency constraints, and can be potentially validated and corrected by domain experts. Our approach is to view the KB as systematically caching answers from a QA system, and the QA system as assembling answers from the KB, the whole process kickstarted with an initial set of textual extractions from the book text itself. Although this research is only in a preliminary stage, we summarize our progress and lessons learned to date.},
booktitle = {Proceedings of the Joint Workshop on Automatic Knowledge Base Construction and Web-Scale Knowledge Extraction},
pages = {74–78},
numpages = {5},
location = {Montreal, Canada},
series = {AKBC-WEKEX '12}
}

@inproceedings{10.5555/2391200.2391215,
author = {Kiddon, Chlo\'{e} and Domingos, Pedro},
title = {Knowledge Extraction and Joint Inference Using Tractable Markov Logic},
year = {2012},
publisher = {Association for Computational Linguistics},
address = {USA},
abstract = {The development of knowledge base creation systems has mainly focused on information extraction without considering how to effectively reason over their databases of facts. One reason for this is that the inference required to learn a probabilistic knowledge base from text at any realistic scale is intractable. In this paper, we propose formulating the joint problem of fact extraction and probabilistic model learning in terms of Tractable Markov Logic (TML), a subset of Markov logic in which inference is low-order polynomial in the size of the knowledge base. Using TML, we can tractably extract new information from text while simultaneously learning a probabilistic knowledge base. We will also describe a testbed for our proposal: creating a biomedical knowledge base and making it available for querying on the Web.},
booktitle = {Proceedings of the Joint Workshop on Automatic Knowledge Base Construction and Web-Scale Knowledge Extraction},
pages = {79–83},
numpages = {5},
location = {Montreal, Canada},
series = {AKBC-WEKEX '12}
}

@inproceedings{10.5555/2391200.2391216,
author = {Lin, Thomas and Mausam and Etzioni, Oren},
title = {Entity Linking at Web Scale},
year = {2012},
publisher = {Association for Computational Linguistics},
address = {USA},
abstract = {This paper investigates entity linking over millions of high-precision extractions from a corpus of 500 million Web documents, toward the goal of creating a useful knowledge base of general facts. This paper is the first to report on entity linking over this many extractions, and describes new opportunities (such as corpus-level features) and challenges we found when entity linking at Web scale. We present several techniques that we developed and also lessons that we learned. We envision a future where information extraction and entity linking are paired to automatically generate knowledge bases with billions of assertions over millions of linked entities.},
booktitle = {Proceedings of the Joint Workshop on Automatic Knowledge Base Construction and Web-Scale Knowledge Extraction},
pages = {84–88},
numpages = {5},
location = {Montreal, Canada},
series = {AKBC-WEKEX '12}
}

@inproceedings{10.5555/2391200.2391217,
author = {Wick, Michael and Schultz, Karl and McCallum, Andrew},
title = {Human-Machine Cooperation with Epistemological DBs: Supporting User Corrections to Knowledge Bases},
year = {2012},
publisher = {Association for Computational Linguistics},
address = {USA},
abstract = {Knowledge bases (KB) provide support for real-world decision making by exposing data in a structured format. However, constructing knowledge bases requires gathering data from many heterogeneous sources. Manual efforts for this task are accurate, but lack scalability, and automated approaches provide good coverage, but are not reliable enough for real-world decision makers to trust. These two approaches to KB construction have complementary strengths: in this paper we propose a novel framework for supporting humanproposed edits to knowledge bases.},
booktitle = {Proceedings of the Joint Workshop on Automatic Knowledge Base Construction and Web-Scale Knowledge Extraction},
pages = {89–94},
numpages = {6},
location = {Montreal, Canada},
series = {AKBC-WEKEX '12}
}

@inproceedings{10.5555/2391200.2391218,
author = {Napoles, Courtney and Gormley, Matthew and Van Durme, Benjamin},
title = {Annotated Gigaword},
year = {2012},
publisher = {Association for Computational Linguistics},
address = {USA},
abstract = {We have created layers of annotation on the English Gigaword v.5 corpus to render it useful as a standardized corpus for knowledge extraction and distributional semantics. Most existing large-scale work is based on inconsistent corpora which often have needed to be re-annotated by research teams independently, each time introducing biases that manifest as results that are only comparable at a high level. We provide to the community a public reference set based on current state-of-the-art syntactic analysis and coreference resolution, along with an interface for programmatic access. Our goal is to enable broader involvement in large-scale knowledge-acquisition efforts by researchers that otherwise may not have had the ability to produce such a resource on their own.},
booktitle = {Proceedings of the Joint Workshop on Automatic Knowledge Base Construction and Web-Scale Knowledge Extraction},
pages = {95–100},
numpages = {6},
location = {Montreal, Canada},
series = {AKBC-WEKEX '12}
}

@inproceedings{10.5555/2391200.2391219,
author = {Balasubramanian, Niranjan and Soderland, Stephen and Mausam and Etzioni, Oren},
title = {Rel-Grams: A Probabilistic Model of Relations in Text},
year = {2012},
publisher = {Association for Computational Linguistics},
address = {USA},
abstract = {We introduce the Rel-grams language model, which is analogous to an n-grams model, but is computed over relations rather than over words. The model encodes the conditional probability of observing a relational tuple R, given that R' was observed in a window of prior relational tuples. We build a database of Rel-grams co-occurence statistics from Re-Verb extractions over 1.8M news wire documents and show that a graphical model based on these statistics is useful for automatically discovering event templates. We make this database freely available and hope it will prove a useful resource for a wide variety of NLP tasks.},
booktitle = {Proceedings of the Joint Workshop on Automatic Knowledge Base Construction and Web-Scale Knowledge Extraction},
pages = {101–105},
numpages = {5},
location = {Montreal, Canada},
series = {AKBC-WEKEX '12}
}

@inproceedings{10.5555/2391200.2391220,
author = {Wang, Daisy Zhe and Chen, Yang and Goldberg, Sean and Grant, Christan and Li, Kun},
title = {Automatic Knowledge Base Construction Using Probabilistic Extraction, Deductive Reasoning, and Human Feedback},
year = {2012},
publisher = {Association for Computational Linguistics},
address = {USA},
abstract = {We envision an automatic knowledge base construction system consisting of three inter-related components. MADden is a knowledge extraction system applying statistical text analysis methods over database systems (DBMS) and massive parallel processing (MPP) frameworks; ProbKB performs probabilistic reasoning over the extracted knowledge to derive additional facts not existing in the original text corpus; CAMeL leverages human intelligence to reduce the uncertainty resulting from both the information extraction and probabilistic reasoning processes.},
booktitle = {Proceedings of the Joint Workshop on Automatic Knowledge Base Construction and Web-Scale Knowledge Extraction},
pages = {106–110},
numpages = {5},
location = {Montreal, Canada},
series = {AKBC-WEKEX '12}
}

@inproceedings{10.5555/2391200.2391221,
author = {Singh, Sameer and Wick, Michael and McCallum, Andrew},
title = {Monte Carlo MCMC: Efficient Inference by Sampling Factors},
year = {2012},
publisher = {Association for Computational Linguistics},
address = {USA},
abstract = {Conditional random fields and other graphical models have achieved state of the art results in a variety of NLP and IE tasks including coreference and relation extraction. Increasingly, practitioners are using models with more complex structure---higher tree-width, larger fanout, more features, and more data---rendering even approximate inference methods such as MCMC inefficient. In this paper we propose an alternative MCMC sampling scheme in which transition probabilities are approximated by sampling from the set of relevant factors. We demonstrate that our method converges more quickly than a traditional MCMC sampler for both marginal and MAP inference. In an author coreference task with over 5 million mentions, we achieve a 13 times speedup over regular MCMC inference.},
booktitle = {Proceedings of the Joint Workshop on Automatic Knowledge Base Construction and Web-Scale Knowledge Extraction},
pages = {111–115},
numpages = {5},
location = {Montreal, Canada},
series = {AKBC-WEKEX '12}
}

@inproceedings{10.5555/2391200.2391222,
author = {Yao, Limin and Riedel, Sebastian and McCallum, Andrew},
title = {Probabilistic Databases of Universal Schema},
year = {2012},
publisher = {Association for Computational Linguistics},
address = {USA},
abstract = {In data integration we transform information from a source into a target schema. A general problem in this task is loss of fidelity and coverage: the source expresses more knowledge than can fit into the target schema, or knowledge that is hard to fit into any schema at all. This problem is taken to an extreme in information extraction (IE) where the source is natural language. To address this issue, one can either automatically learn a latent schema emergent in text (a brittle and ill-defined task), or manually extend schemas. We propose instead to store data in a probabilistic database of universal schema. This schema is simply the union of all source schemas, and the probabilistic database learns how to predict the cells of each source relation in this union. For example, the database could store Freebase relations and relations that correspond to natural language surface patterns. The database would learn to predict what freebase relations hold true based on what surface patterns appear, and vice versa. We describe an analogy between such databases and collaborative filtering models, and use it to implement our paradigm with probabilistic PCA, a scalable and effective collaborative filtering method.},
booktitle = {Proceedings of the Joint Workshop on Automatic Knowledge Base Construction and Web-Scale Knowledge Extraction},
pages = {116–121},
numpages = {6},
location = {Montreal, Canada},
series = {AKBC-WEKEX '12}
}

@inproceedings{10.5555/2391200.2391223,
author = {Gordon, Jonathan and Schubert, Lenhart K.},
title = {Using Textual Patterns to Learn Expected Event Frequencies},
year = {2012},
publisher = {Association for Computational Linguistics},
address = {USA},
abstract = {Commonsense reasoning requires knowledge about the frequency with which ordinary events and activities occur: How often do people eat a sandwich, go to sleep, write a book, or get married? This paper introduces work to acquire a knowledge base pairing factoids about such events with frequency categories learned from simple textual patterns. We are releasing a collection of the resulting event frequencies, which are evaluated for accuracy, and we demonstrate an initial application of the results to the problem of knowledge refinement.},
booktitle = {Proceedings of the Joint Workshop on Automatic Knowledge Base Construction and Web-Scale Knowledge Extraction},
pages = {122–127},
numpages = {6},
location = {Montreal, Canada},
series = {AKBC-WEKEX '12}
}

license: Unlicense

repository: goyalkaraniit/acm-cr

repo_name: goyalkaraniit/acm-cr


text:
/*!\file TriaInput.c
 * \brief: implementation of the TriaInput object
 */

#ifdef HAVE_CONFIG_H
	#include <config.h>
#else
#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
#endif

#include "../classes.h"
#include "../../shared/shared.h"

/*TriaInput constructors and destructor*/
TriaInput::TriaInput(){/*{{{*/
	values = NULL;
}
/*}}}*/
TriaInput::TriaInput(int in_enum_type,IssmDouble* in_values,int interpolation_type_in){/*{{{*/

	/*Set Enum*/
	this->enum_type=in_enum_type;
	this->interpolation_type=interpolation_type_in;

	int numnodes = this->NumberofNodes(this->interpolation_type);

	/*Set values*/
	if (numnodes > 0){
		this->values=xNew<IssmDouble>((unsigned int)numnodes);
		for(int i=0;i<numnodes;i++) values[i]=in_values[i];
	}
	else{
		this->values = NULL;
	}
}
/*}}}*/
TriaInput::~TriaInput(){/*{{{*/
	xDelete<IssmDouble>(this->values);
}
/*}}}*/

/*Object virtual functions definitions:*/
Object* TriaInput::copy() {/*{{{*/

	return new TriaInput(this->enum_type,this->values,this->interpolation_type);

}
/*}}}*/
void TriaInput::DeepEcho(void){/*{{{*/

	_printf_(setw(15)<<"   TriaInput "<<setw(25)<<left<<EnumToStringx(this->enum_type)<<" [");
	for(int i=0;i<this->NumberofNodes(this->interpolation_type);i++) _printf_(" "<<this->values[i]);
	_printf_("] ("<<EnumToStringx(this->interpolation_type)<<")\n");
}
/*}}}*/
void TriaInput::Echo(void){/*{{{*/
	this->DeepEcho();
}
/*}}}*/
int  TriaInput::Id(void){ return -1; }/*{{{*/
/*}}}*/
void TriaInput::Marshall(char** pmarshalled_data,int* pmarshalled_data_size, int marshall_direction){ /*{{{*/

	MARSHALLING_ENUM(TriaInputEnum);

	MARSHALLING(enum_type);
	MARSHALLING(interpolation_type);

	int numnodes = this->NumberofNodes(this->interpolation_type);
	if(numnodes > 0){
		MARSHALLING_DYNAMIC(this->values,IssmDouble,numnodes)
	}
	else this->values = NULL;
}
/*}}}*/
int  TriaInput::ObjectEnum(void){/*{{{*/

	return TriaInputEnum;

}
/*}}}*/

/*TriaInput management*/
int TriaInput::InstanceEnum(void){/*{{{*/

	return this->enum_type;

}
/*}}}*/
int  TriaInput::GetResultArraySize(void){/*{{{*/

	return 1;

}
/*}}}*/
int  TriaInput::GetResultInterpolation(void){/*{{{*/

	if(this->interpolation_type==P0Enum){
		return P0Enum;
	}
	return P1Enum;

}
/*}}}*/
int  TriaInput::GetResultNumberOfNodes(void){/*{{{*/

	return this->NumberofNodes(this->interpolation_type);

}
/*}}}*/
void TriaInput::ResultToPatch(IssmDouble* values,int nodesperelement,int sid){/*{{{*/

	int numnodes = this->NumberofNodes(this->interpolation_type);

	/*Some checks*/
	_assert_(values);
	_assert_(numnodes==nodesperelement);

	/*Fill in arrays*/
	for(int i=0;i<numnodes;i++) values[sid*numnodes + i] = this->values[i];
}
/*}}}*/
Input* TriaInput::SpawnSegInput(int index1,int index2){/*{{{*/

	/*output*/
	SegInput* outinput=NULL;

	if(this->interpolation_type==P0Enum){
		outinput=new SegInput(this->enum_type,&this->values[0],P0Enum);
	}
	else{
		/*Assume P1 interpolation only for now*/
		IssmDouble newvalues[2];

		/*Create array of indices depending on location (0=base 1=surface)*/
		newvalues[0]=this->values[index1];
		newvalues[1]=this->values[index2];

		/*Create new Seg input*/
		outinput=new SegInput(this->enum_type,&newvalues[0],P1Enum);
	}

	/*Assign output*/
	return outinput;

}
/*}}}*/
Input* TriaInput::SpawnTriaInput(int index1,int index2,int index3){/*{{{*/

	/*output*/
	TriaInput* outinput=NULL;

	/*Create new Tria input (copy of current input)*/
	outinput=new TriaInput(this->enum_type,&this->values[0],this->interpolation_type);

	/*Assign output*/
	return outinput;

}
/*}}}*/

/*Object functions*/
void TriaInput::ChangeEnum(int newenumtype){/*{{{*/
	this->enum_type=newenumtype;
}
/*}}}*/
void TriaInput::GetInputAllTimeAverages(IssmDouble** pvalues,IssmDouble** ptimes, int* pnumtimes){/*{{{*/

	IssmDouble* outvalues=NULL;
	IssmDouble* times=NULL;
	int         numtimes;

	/*this is not a transient forcing, so we only have 1 value, steady state: */
	numtimes=1;
	outvalues=xNew<IssmDouble>(1);
	times=xNew<IssmDouble>(1);

	this->GetInputAverage(&outvalues[0]);
	times[0]=0.; /*we don't have a time*/

	*pvalues=outvalues;
	*ptimes=times;
	*pnumtimes=numtimes;
}
/*}}}*/
void TriaInput::GetInputAverage(IssmDouble* pvalue){/*{{{*/

	int        numnodes  = this->NumberofNodes(this->interpolation_type);
	IssmDouble numnodesd = reCast<int,IssmDouble>(numnodes);
	IssmDouble value     = 0.;

	for(int i=0;i<numnodes;i++) value+=values[i];
	value = value/numnodesd;

	*pvalue=value;
}
/*}}}*/
void TriaInput::GetInputDerivativeAverageValue(IssmDouble* derivativevalues, IssmDouble* xyz_list){/*{{{*/

	int        numnodes  = this->NumberofNodes(this->interpolation_type);
	IssmDouble numnodesd = reCast<int,IssmDouble>(numnodes);
	IssmDouble dvalue[3];

	derivativevalues[0] = 0.;
	derivativevalues[1] = 0.;

	GaussTria* gauss=new GaussTria();
	for(int iv=0;iv<numnodes;iv++){
		gauss->GaussNode(this->interpolation_type,iv);
		this->GetInputDerivativeValue(&dvalue[0],xyz_list,gauss);

		derivativevalues[0] += dvalue[0]/numnodesd;
		derivativevalues[1] += dvalue[1]/numnodesd;
	}
	delete gauss;
}
/*}}}*/
void TriaInput::GetInputDerivativeValue(IssmDouble* p, IssmDouble* xyz_list, Gauss* gauss){/*{{{*/

	/*Call TriaRef function*/
	_assert_(gauss->Enum()==GaussTriaEnum);
	TriaRef::GetInputDerivativeValue(p,&values[0],xyz_list,(GaussTria*)gauss,this->interpolation_type);
}
/*}}}*/
void TriaInput::GetInputUpToCurrentTimeAverages(IssmDouble** pvalues, IssmDouble** ptimes, int* pnumtimes, IssmDouble currenttime){/*{{{*/

	IssmDouble* outvalues=NULL;
	IssmDouble* times=NULL;
	int         numtimes;

	/*this is not a transient forcing, so we only have 1 value, steady state: */
	numtimes=1;
	outvalues=xNew<IssmDouble>(1);
	times=xNew<IssmDouble>(1);

	this->GetInputAverage(&outvalues[0]);
	times[0]=currenttime; /*we don't have a time*/

	*pvalues=outvalues;
	*ptimes=times;
	*pnumtimes=numtimes;
}
/*}}}*/
void TriaInput::GetInputValue(IssmDouble* pvalue,Gauss* gauss){/*{{{*/

	/*Call TriaRef function*/
	_assert_(gauss->Enum()==GaussTriaEnum);
	TriaRef::GetInputValue(pvalue,&values[0],(GaussTria*)gauss,this->interpolation_type);

}
/*}}}*/

/*Intermediary*/
void TriaInput::AXPY(Input* xinput,IssmDouble scalar){/*{{{*/

	const int numnodes=this->NumberofNodes(this->interpolation_type);
	TriaInput*  xtriainput=NULL;

	/*xinput is of the same type, so cast it: */
	if(xinput->ObjectEnum()!=TriaInputEnum) _error_("Operation not permitted because xinput is of type " << EnumToStringx(xinput->ObjectEnum()));
	xtriainput=(TriaInput*)xinput;
	if(xtriainput->interpolation_type!=this->interpolation_type) _error_("Operation not permitted because xinput is of type " << EnumToStringx(xinput->ObjectEnum()));

	/*Carry out the AXPY operation depending on type:*/
	for(int i=0;i<numnodes;i++)this->values[i]=this->values[i]+scalar*xtriainput->values[i];

}
/*}}}*/
void TriaInput::Configure(Parameters* parameters){/*{{{*/
	/*do nothing: */
}
/*}}}*/
void TriaInput::Constrain(IssmDouble cm_min, IssmDouble cm_max){/*{{{*/

	int i;
	const int numnodes=this->NumberofNodes(this->interpolation_type);

	if(!xIsNan<IssmDouble>(cm_min)) for(i=0;i<numnodes;i++)if (this->values[i]<cm_min)this->values[i]=cm_min;
	if(!xIsNan<IssmDouble>(cm_max)) for(i=0;i<numnodes;i++)if (this->values[i]>cm_max)this->values[i]=cm_max;

}
/*}}}*/
void TriaInput::ConstrainMin(IssmDouble minimum){/*{{{*/

	int numnodes = this->NumberofNodes(this->interpolation_type);
	for(int i=0;i<numnodes;i++) if (values[i]<minimum) values[i]=minimum;
}
/*}}}*/
void TriaInput::GetVectorFromInputs(Vector<IssmDouble>* vector,int* doflist){/*{{{*/
	const int numvertices=3;
	vector->SetValues(numvertices,doflist,this->values,INS_VAL);
} /*}}}*/
IssmDouble TriaInput::InfinityNorm(void){/*{{{*/

	/*Output*/
	IssmDouble norm=0.;
	int numnodes=this->NumberofNodes(this->interpolation_type);

	for(int i=0;i<numnodes;i++) if(fabs(values[i])>norm) norm=fabs(values[i]);
	return norm;
}
/*}}}*/
IssmDouble TriaInput::Max(void){/*{{{*/

	int  numnodes=this->NumberofNodes(this->interpolation_type);
	IssmDouble max=values[0];

	for(int i=1;i<numnodes;i++){
		if(values[i]>max) max=values[i];
	}
	return max;
}
/*}}}*/
IssmDouble TriaInput::MaxAbs(void){/*{{{*/

	int  numnodes=this->NumberofNodes(this->interpolation_type);
	IssmDouble max=fabs(values[0]);

	for(int i=1;i<numnodes;i++){
		if(fabs(values[i])>max) max=fabs(values[i]);
	}
	return max;
}
/*}}}*/
IssmDouble TriaInput::Min(void){/*{{{*/

	const int  numnodes=this->NumberofNodes(this->interpolation_type);
	IssmDouble min=values[0];

	for(int i=1;i<numnodes;i++){
		if(values[i]<min) min=values[i];
	}
	return min;
}
/*}}}*/
IssmDouble TriaInput::MinAbs(void){/*{{{*/

	const int  numnodes=this->NumberofNodes(this->interpolation_type);
	IssmDouble min=fabs(values[0]);

	for(int i=1;i<numnodes;i++){
		if(fabs(values[i])<min) min=fabs(values[i]);
	}
	return min;
}
/*}}}*/
Input* TriaInput::PointwiseMax(Input* inputB){/*{{{*/

	/*Ouput*/
	TriaInput* outinput=NULL;

	/*Intermediaries*/
	int         i;
	TriaInput  *xinputB   = NULL;
	const int   numnodes  = this->NumberofNodes(this->interpolation_type);
	IssmDouble *maxvalues = xNew<IssmDouble>(numnodes);

	/*Check that inputB is of the same type*/
	if(inputB->ObjectEnum()!=TriaInputEnum) _error_("Operation not permitted because inputB is of type " << EnumToStringx(inputB->ObjectEnum()));
	xinputB=(TriaInput*)inputB;
	if(xinputB->interpolation_type!=this->interpolation_type) _error_("Operation not permitted because inputB is of type " << EnumToStringx(xinputB->interpolation_type));

	/*Create point wise max*/
	for(i=0;i<numnodes;i++){
		if(this->values[i] < xinputB->values[i]) maxvalues[i]=xinputB->values[i];
		else maxvalues[i]=this->values[i];
	}

	/*Create new Tria vertex input (copy of current input)*/
	outinput=new TriaInput(this->enum_type,&maxvalues[0],this->interpolation_type);

	/*Return output pointer*/
	xDelete<IssmDouble>(maxvalues);
	return outinput;

}
/*}}}*/
Input* TriaInput::PointwiseMin(Input* inputB){/*{{{*/

	/*Ouput*/
	TriaInput* outinput=NULL;

	/*Intermediaries*/
	int         i;
	TriaInput  *xinputB   = NULL;
	const int   numnodes  = this->NumberofNodes(this->interpolation_type);
	IssmDouble *minvalues = xNew<IssmDouble>(numnodes);

	/*Check that inputB is of the same type*/
	if(inputB->ObjectEnum()!=TriaInputEnum)       _error_("Operation not permitted because inputB is of type " << EnumToStringx(inputB->ObjectEnum()));
	xinputB=(TriaInput*)inputB;
	if(xinputB->interpolation_type!=this->interpolation_type) _error_("Operation not permitted because inputB is of type " << EnumToStringx(xinputB->interpolation_type));

	/*Create point wise min*/
	for(i=0;i<numnodes;i++){
		if(this->values[i] > xinputB->values[i]) minvalues[i]=xinputB->values[i];
		else minvalues[i]=this->values[i];
	}

	/*Create new Tria vertex input (copy of current input)*/
	outinput=new TriaInput(this->enum_type,&minvalues[0],this->interpolation_type);

	/*Return output pointer*/
	xDelete<IssmDouble>(minvalues);
	return outinput;

}
/*}}}*/
Input* TriaInput::PointwiseDivide(Input* inputB){/*{{{*/

	/*Ouput*/
	TriaInput* outinput=NULL;

	/*Intermediaries*/
	TriaInput *xinputB  = NULL;
	const int   numnodes = this->NumberofNodes(this->interpolation_type);

	/*Check that inputB is of the same type*/
	if(inputB->ObjectEnum()!=TriaInputEnum)     _error_("Operation not permitted because inputB is of type " << EnumToStringx(inputB->ObjectEnum()));
	xinputB=(TriaInput*)inputB;
	if(xinputB->interpolation_type!=this->interpolation_type) _error_("Operation not permitted because inputB is of type " << EnumToStringx(xinputB->interpolation_type));

	/*Allocate intermediary*/
	IssmDouble* AdotBvalues=xNew<IssmDouble>(numnodes);

	/*Create point wise division*/
	for(int i=0;i<numnodes;i++){
		_assert_(xinputB->values[i]!=0);
		AdotBvalues[i]=this->values[i]/xinputB->values[i];
	}

	/*Create new Tria vertex input (copy of current input)*/
	outinput=new TriaInput(this->enum_type,AdotBvalues,this->interpolation_type);

	/*Return output pointer*/
	xDelete<IssmDouble>(AdotBvalues);
	return outinput;

}
/*}}}*/
void TriaInput::Scale(IssmDouble scale_factor){/*{{{*/

	const int numnodes=this->NumberofNodes(this->interpolation_type);
	for(int i=0;i<numnodes;i++)values[i]=values[i]*scale_factor;
}
/*}}}*/
void TriaInput::Set(IssmDouble setvalue){/*{{{*/

	const int numnodes=this->NumberofNodes(this->interpolation_type);
	for(int i=0;i<numnodes;i++)values[i]=setvalue;
}
/*}}}*/
void TriaInput::SquareMin(IssmDouble* psquaremin,Parameters* parameters){/*{{{*/

	int        numnodes=this->NumberofNodes(this->interpolation_type);
	IssmDouble squaremin;

	/*Now, figure out minimum of valuescopy: */
	squaremin=pow(this->values[0],2);
	for(int i=1;i<numnodes;i++){
		if(pow(this->values[i],2)<squaremin)squaremin=pow(this->values[i],2);
	}
	/*Assign output pointers:*/
	*psquaremin=squaremin;
}
/*}}}*/

repository: eyhl/issm

license_type: permissive

repo_name: eyhl/issm

branch_name: refs/heads/master

extension: cpp


text:
#include "TURIPserverSPI.h"

using namespace ns_TURIPserverSPI;

struct st_TURIPserverSPI_buffer ns_TURIPserverSPI::rxBuf;
struct st_TURIPserverSPI_buffer ns_TURIPserverSPI::txBuf;
cl_TURIPserverSPI TURIPserverSPI;

cl_TURIPserverSPI::cl_TURIPserverSPI(){
  rxBuf.maxLength = 32; rxBuf.readPoint = 0; rxBuf.writePoint = 0;
  txBuf.maxLength = 32; txBuf.readPoint = 0; txBuf.writePoint = 0;
  rxBuf.buffer = new uint8_t[rxBuf.maxLength];
  txBuf.buffer = new uint8_t[txBuf.maxLength];
}

void cl_TURIPserverSPI::begin(){
  #ifdef __AVR__
  // Setting SPI
  DDRB = DDRB | 0B00010000;  // Set "OUTPUT" MISO
  PORTB = PORTB | 0B00011000;  // Pullup MISO,MOSI
  SPDR = 0xff;
  SPCR = _BV(SPE) | _BV(SPIE);
  // Setting SS interrupt
  // PCMSK0 = _BV(PCINT1);
  // PCICR = PCICR | _BV(PCIE0);
  sei();
  #endif
}

void cl_TURIPserverSPI::update(){
  // If SPI is desabled, buffers are reseted.
  if(digitalRead(TURIPSERVER_PIN_SS) == HIGH){
    rxBuf.writePoint = 0;
    rxBuf.readPoint = 0;
    txBuf.writePoint = 0;
    txBuf.readPoint = 0;
    #ifdef __AVR__
    SPDR = 0xff;
    #endif
    return;
  }

  // 送信処理が終わるまではその他の処理はしない
  if(txBuf.readPoint != txBuf.writePoint){
    return;
  }

  if(rxBuf.writePoint){
    // rxバッファに何かしら入っている->有効なデータの可能性あり
    // ヘッダを解析してデータが足りているか確認し、足りている場合は実際の処理を行う
    TURIPport* port = TURIPserver.getPort(rxBuf.buffer[0] & 0x7f);
    if(port == NULL){
      noInterrupts();
      //バッファのリセット
      rxBuf.writePoint = 0;
      rxBuf.readPoint = 0;
      txBuf.writePoint = 0;
      txBuf.readPoint = 0;
      // NACK送信
      txBuf.buffer[txBuf.writePoint++] = 0x40;
      interrupts();
    }else if(rxBuf.buffer[0]&0x80){
      //Writeモード(client->server)の処理
      int sizeofData = port->cacheSize;
      if(rxBuf.writePoint > sizeofData){
        // データが十分に揃っている場合
        //　ユーザー領域へデータをコピー
        port->receive(&rxBuf.buffer[1]);
        noInterrupts();
        //バッファのリセット
        rxBuf.writePoint = 0;
        rxBuf.readPoint = 0;
        txBuf.writePoint = 0;
        txBuf.readPoint = 0;
        // Set "Data type" bits.
        uint8_t typeFlags = (uint8_t)port->type;
        // ACK送信
        txBuf.buffer[txBuf.writePoint++] = 0x00 | typeFlags;
        interrupts();
      }
    }else{
      // Readモード(server->client)の処理
      // ユーザー領域を送信バッファへコピー
      noInterrupts();
      // バッファのリセット
      rxBuf.writePoint = 0;
      rxBuf.readPoint = 0;
      txBuf.writePoint = 0;
      txBuf.readPoint = 0;
      // Set "Data type" bits.
      uint8_t typeFlags = (uint8_t)port->type;
      // 転送
      txBuf.buffer[txBuf.writePoint++] = 0x00 | typeFlags;
      int sizeofData = port->cacheSize;
      port->transmit(&txBuf.buffer[txBuf.writePoint], txBuf.maxLength - 1);
      txBuf.writePoint += sizeofData;
      // Serial.println(port->read<long>(), HEX);
      // for(int i=sizeofData; i>0; i--){
      //   Serial.print(txBuf.buffer[txBuf.writePoint - i], HEX);
      //   Serial.print(" ");
      // }
      // Serial.println();

      interrupts();
    }
  }
}

license: MIT

repository: turippj/TURIPlibrariesForArduino

repo_name: turippj/TURIPlibrariesForArduino

gha_license_id: MIT


text:
// Copyright (C) 2012-2014 by krepa098. All rights reserved.
// Use of this source code is governed by a zlib-style
// license that can be found in the license.txt file.

package gosfml2

// #cgo LDFLAGS: -lcsfml-window -lcsfml-graphics -lcsfml-audio -lcsfml-system
import "C"

license: MIT,Zlib

repository: manyminds/gosfml

detected_licenses: MIT Zlib

repo_name: manyminds/gosfml

gha_language: Go

extension: go


text:
#include "exercisedata.h"
#include <QDebug>

ExerciseData::ExerciseData(int exerciseId, QString exerciseName, QString exerciseDescription, QString exerciseCategory, QString exerciseImage)
{
    m_exerciseId = exerciseId;
    m_exerciseName = exerciseName;
    m_exerciseDescription = exerciseDescription;
    m_exerciseCategory = exerciseCategory;
    m_exerciseImage = exerciseImage;
}

ExerciseData::~ExerciseData() { }

int ExerciseData::getExerciseId() { return m_exerciseId; }

QString ExerciseData::getExerciseName() { return m_exerciseName; }

QString ExerciseData::getExerciseDescription() { return m_exerciseDescription; }

QString ExerciseData::getExerciseCategory() { return m_exerciseCategory; }

QString ExerciseData::getExerciseImage() { return m_exerciseImage; }

void ExerciseData::setExerciseId(int exerciseId)
{
    if (m_exerciseId != exerciseId) {
        m_exerciseId = exerciseId;
    }
}

void ExerciseData::setExerciseName(QString exerciseName)
{
    if (m_exerciseName != exerciseName) {
        m_exerciseName = exerciseName;
    }
}

void ExerciseData::setExerciseDescription(QString exerciseDescription)
{
    if (m_exerciseDescription != exerciseDescription) {
        m_exerciseDescription = exerciseDescription;
    }
}

void ExerciseData::setExerciseCategory(QString exerciseCategory)
{
    if (m_exerciseCategory != exerciseCategory) {
        m_exerciseCategory = exerciseCategory;
    }
}

void ExerciseData::setExerciseImage(QString exerciseImage)
{
    if (m_exerciseImage != exerciseImage) {
        m_exerciseImage = exerciseImage;
    }
}

repository: sailfish-os-apps/harbour-salifish

repo_name: sailfish-os-apps/harbour-salifish


text:
/* LXArtNet.cpp
   Copyright 2015-2015 by Claude Heintz Design
   see LXDMXEthernet.h for license

   LXArtNet partially implements the Art-Net Ethernet Communication Standard.
   http://www.artisticlicence.com

   LXArtNet supports capturing a single universe of DMX data
   from Art-Net packets read from UDP.
   LXArtNet will automatically respond to ArtPoll packets
   by sending a unicast reply directly to the poll.

   LXArtNet does not support merge and will only accept ArtDMX output packets
   from the first IP address that it receives a packet from.
   This can be reset by sending an ArtAddress cancel merge command.

	Art-Net(TM) Designed by and Copyright Artistic Licence Holdings Ltd.
*/

#include "LXArtNet.h"

//shared static buffer for sending poll replies
uint8_t LXArtNet::_reply_buffer[ARTNET_REPLY_SIZE];

LXArtNet::LXArtNet ( IPAddress address )
{
	initialize(0);
	setLocalIP( address );
    _broadcast_address = INADDR_NONE;
}

LXArtNet::LXArtNet ( IPAddress address, IPAddress subnet_mask )
{
	initialize(0);
	setLocalIP( address, subnet_mask );
}

LXArtNet::LXArtNet ( IPAddress address, IPAddress subnet_mask, uint8_t* buffer )
{
	initialize(buffer);
	setLocalIP( address, subnet_mask );

    uint32_t a = (uint32_t) address;
    uint32_t s = (uint32_t) subnet_mask;
    _broadcast_address = IPAddress(a | ~s);
}

LXArtNet::~LXArtNet ( void )
{
   if ( _owns_buffer ) {		// if we created this buffer, then free the memory
		free(_packet_buffer);
	}
	if ( _using_htp ) {
		free(_dmx_buffer_a);
		free(_dmx_buffer_b);
		free(_dmx_buffer_c);
	}
}

void  LXArtNet::initialize  ( uint8_t* b ) {
	if ( b == 0 ) {
		// create buffer
		_packet_buffer = (uint8_t*) malloc(ARTNET_BUFFER_MAX);
		_owns_buffer = 1;
	} else {
		// external buffer.  Size MUST be >=ARTNET_BUFFER_MAX
		_packet_buffer = b;
		_owns_buffer = 0;
	}

    memset(_packet_buffer, 0, ARTNET_BUFFER_MAX);

    _using_htp    = 0;
    _dmx_buffer_a = 0;
    _dmx_buffer_b = 0;
    _dmx_buffer_c = 0;

    _dmx_slots   = 0;
    _dmx_slots_a = 0;
    _dmx_slots_b = 0;
    _universe    = 0;
    _net         = 0;
    _sequence    = 1;

     _dmx_sender = INADDR_NONE;
     _dmx_sender_b = INADDR_NONE;

    initializePollReply();

    _art_tod_req_callback = 0;
    _art_rdm_callback = 0;
    _art_cmd_callback = 0;
}

uint8_t  LXArtNet::universe ( void ) {
	return _universe;
}

void LXArtNet::setUniverse ( uint8_t u ) {
	_universe = u;
}

void LXArtNet::setSubnetUniverse ( uint8_t s, uint8_t u ) {
   _universe = ((s & 0x0f) << 4) | ( u & 0x0f);
}

void LXArtNet::setUniverseAddress ( uint8_t u ) {
	if ( u != 0x7f ) {
	   if ( u & 0x80 ) {
	     _universe = (_universe & 0xf0) | (u & 0x07);
	   }
	}
}

void LXArtNet::setSubnetAddress ( uint8_t u ) {
	if ( u != 0x7f ) {
	   if ( u & 0x80 ) {
	     _universe = (_universe & 0x0f) | ((u & 0x07) << 4);
	   }
	}
}

void LXArtNet::setNetAddress ( uint8_t s ) {
	if ( s & 0x80 ) {
	  _net = (s & 0x7F);
	}
}

void LXArtNet::setLocalIP ( IPAddress a ) {
	_my_address = a;
	_reply_buffer[10] = ((uint32_t)_my_address) & 0xff;      //ip address
  	_reply_buffer[11] = ((uint32_t)_my_address) >> 8;
  	_reply_buffer[12] = ((uint32_t)_my_address) >> 16;
  	_reply_buffer[13] = ((uint32_t)_my_address) >>24;
}

void LXArtNet::setLocalIP ( IPAddress a, IPAddress sn ) {
	setLocalIP(a);
	// calculate broadcast address
	uint32_t a32 = (uint32_t) a;
    uint32_t s32 = (uint32_t) sn;
    _broadcast_address = IPAddress( a32 | ~s32 );
}

void LXArtNet::enableHTP() {
#if defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__) || defined(__AVR_ATmega328__)
	// not enough memory on these to allocate these buffers
#else
	if ( ! _using_htp ) {
		_dmx_buffer_a = (uint8_t*) malloc(DMX_UNIVERSE_SIZE);
		_dmx_buffer_b = (uint8_t*) malloc(DMX_UNIVERSE_SIZE);
		_dmx_buffer_c = (uint8_t*) malloc(DMX_UNIVERSE_SIZE);
		for(int i=0; i<DMX_UNIVERSE_SIZE; i++) {
		   _dmx_buffer_a[i] = 0;
		   _dmx_buffer_b[i] = 0;
		   _dmx_buffer_c[i] = 0;
		}
		_using_htp = 1;
	}
#endif
}

int  LXArtNet::numberOfSlots ( void ) {
	return _dmx_slots;
}

void LXArtNet::setNumberOfSlots ( int n ) {
	_dmx_slots = n;
}

uint8_t LXArtNet::getSlot ( int slot ) {
	return _packet_buffer[ARTNET_ADDRESS_OFFSET+slot];
}

uint8_t LXArtNet::getHTPSlot ( int slot ) {
	return _dmx_buffer_c[slot-1];
}

void LXArtNet::setSlot ( int slot, uint8_t value ) {
	_packet_buffer[ARTNET_ADDRESS_OFFSET+slot] = value;
}

uint8_t* LXArtNet::dmxData( void ) {
	return &_packet_buffer[ARTNET_ADDRESS_OFFSET+1];
}

uint8_t* LXArtNet::replyData( void ) {
	return _reply_buffer;
}

char* LXArtNet::shortName( void ) {
	return (char*)&_reply_buffer[26];
}

char* LXArtNet::longName( void ) {
	return (char*)&_reply_buffer[44];
}

void LXArtNet::setNodeName( const char* name ) {
	//strcpy((char*)&_reply_buffer[26], name);
	strcpy(longName(), name);
}

uint8_t LXArtNet::readDMXPacket ( UDP* eUDP ) {
   uint16_t opcode = readArtNetPacket(eUDP);
   if ( opcode == ARTNET_ART_DMX ) {
   	return RESULT_DMX_RECEIVED;
   }
   return RESULT_NONE;
}

uint8_t LXArtNet::readDMXPacketContents ( UDP* eUDP, int packetSize ) {
	if ( packetSize > 0 ) {
		uint16_t opcode = readArtNetPacketContents(eUDP, packetSize);
		if ( opcode == ARTNET_ART_DMX ) {
			return RESULT_DMX_RECEIVED;
		}
		if ( opcode == ARTNET_ART_POLL ) {
			return RESULT_PACKET_COMPLETE;
		}
   }
   return RESULT_NONE;
}

/*
  attempts to read a packet from the supplied UDP object
  returns opcode
  sends ArtPollReply with IPAddress if packet is ArtPoll
  replies directly to sender unless reply_ip != INADDR_NONE allowing specification of broadcast
  only returns ARTNET_ART_DMX if packet contained dmx data for this universe
  Packet size checks that packet is >= expected size to allow zero termination or padding
*/
uint16_t LXArtNet::readArtNetPacket ( UDP* eUDP ) {
	uint16_t opcode = ARTNET_NOP;
	int packetSize = eUDP->parsePacket();
	if ( packetSize > 0 ) {
		packetSize = eUDP->read(_packet_buffer, ARTNET_BUFFER_MAX);
		opcode = readArtNetPacketContents(eUDP, packetSize);
	}
	return opcode;
}

uint16_t LXArtNet::readArtNetPacketContents ( UDP* eUDP, int packetSize ) {
   if ( ! _using_htp ) {
		_dmx_slots = 0;
		/* Buffer now may not contain dmx data for desired universe.
		After reading the packet into the buffer, check to make sure
		that it is an Art-Net packet and retrieve the opcode that
		tells what kind of message it is.                            */
	}

	uint16_t opcode = parse_header();
	switch ( opcode ) {
		case ARTNET_ART_DMX:
		   opcode = ARTNET_NOP;
			// ignore protocol version [10] hi byte [11] lo byte sequence[12], physical[13]
			if (( _packet_buffer[14] == _universe ) && ( _packet_buffer[15] == _net )) {
				packetSize -= 18;
				uint16_t slots = _packet_buffer[17];
				slots += _packet_buffer[16] << 8;
				if ( packetSize >= slots ) {					// double check we got all expected
					opcode = readArtDMX(eUDP, slots, packetSize);      // returns ARTNET_ART_DMX
				}
			}   // matched universe/net
			break;
		case ARTNET_ART_ADDRESS:
			if (( packetSize >= 107 ) && ( _packet_buffer[11] >= 14 )) {  //protocol version [10] hi byte [11] lo byte
				opcode = parse_art_address( eUDP );
				send_art_poll_reply( eUDP );
			}
			break;
		case ARTNET_ART_POLL:
			if (( packetSize >= 14 ) && ( _packet_buffer[11] >= 14 )) {
				send_art_poll_reply( eUDP );
			}
			break;
		case ARTNET_ART_TOD_REQUEST:
		   opcode = ARTNET_NOP;
		   if (( packetSize >= 25 ) && ( _packet_buffer[11] >= 14 )) {
				opcode = parse_art_tod_request( eUDP );
			}
			break;
		case ARTNET_ART_TOD_CONTROL:
		   opcode = ARTNET_NOP;
		   if (( packetSize >= 24 ) && ( _packet_buffer[11] >= 14 )) {
				opcode = parse_art_tod_control( eUDP );
			}
			break;
		case ARTNET_ART_RDM:
		   opcode = ARTNET_NOP;
		   if (( packetSize >= 24 ) && ( _packet_buffer[11] >= 14 )) {
				opcode = parse_art_rdm( eUDP );
			}
			break;
		case ARTNET_ART_CMD:
			parse_art_cmd( eUDP );
			break;
	}
   return opcode;
}

uint16_t LXArtNet::readArtDMX ( UDP* eUDP, uint16_t slots, int packetSize ) {
	uint16_t opcode = ARTNET_NOP;
	if ( _using_htp ) {
	   if ( (uint32_t)_dmx_sender == 0 ) {		//if first sender, remember address
			_dmx_sender = eUDP->remoteIP();
			for(int j=0; j<DMX_UNIVERSE_SIZE; j++) {
				_dmx_buffer_b[j] = 0;	//insure clear buffer 'b' so cancel merge works properly
			}
	   }
		if ( _dmx_sender == eUDP->remoteIP() ) {
			_dmx_slots_a  = slots;
			if ( _dmx_slots_a > _dmx_slots_b ) {
				_dmx_slots = _dmx_slots_a;
			} else {
				_dmx_slots = _dmx_slots_b;
			}
			int di;
			int dc = _dmx_slots;
			int dt = ARTNET_ADDRESS_OFFSET + 1;
			  for (di=0; di<dc; di++) {
				if ( di < slots ) {								// total slots may be greater than slots in this packet
					_dmx_buffer_a[di] = _packet_buffer[dt+di];
				}  else {										// don't read beyond end of received slots
					_dmx_buffer_a[di] = 0;						// set remainder to zero
				}
				if ( _dmx_buffer_a[di] > _dmx_buffer_b[di] ) {
					_dmx_buffer_c[di] = _dmx_buffer_a[di];
				} else {
					_dmx_buffer_c[di] = _dmx_buffer_b[di];
				}
			}
			opcode = ARTNET_ART_DMX;
		} else { 												// did not match sender a
			if ( (uint32_t)_dmx_sender_b == 0 ) {		// if 2nd sender, remember address
				_dmx_sender_b = eUDP->remoteIP();
			}
			if ( _dmx_sender_b == eUDP->remoteIP() ) {
			  _dmx_slots_b  = slots;
				if ( _dmx_slots_a > _dmx_slots_b ) {
					_dmx_slots = _dmx_slots_a;
				} else {
					_dmx_slots = _dmx_slots_b;
				}
			  int di;
			  int dc = _dmx_slots;
			  int dt = ARTNET_ADDRESS_OFFSET + 1;
			  for (di=0; di<dc; di++) {
				if ( di < slots ) {								//total slots may be greater than slots in this packet
					_dmx_buffer_b[di] = _packet_buffer[dt+di];
				}  else {											//don't read beyond end of received slots
					_dmx_buffer_b[di] = 0;							//set remainder to zero
				}
				if ( _dmx_buffer_a[di] > _dmx_buffer_b[di] ) {
					_dmx_buffer_c[di] = _dmx_buffer_a[di];
				} else {
					_dmx_buffer_c[di] = _dmx_buffer_b[di];
				}
			  }
			  opcode = ARTNET_ART_DMX;
			}  // matched sender b
		}     // did not match sender a
	} else {								    // NOTE _using_htp only allow one sender
#if defined ( NO_HTP_IS_SINGLE_SENDER )
		if ( (uint32_t)_dmx_sender == 0 ) {		// if first sender, remember address
			_dmx_sender = eUDP->remoteIP();
		}
		if ( _dmx_sender == eUDP->remoteIP() ) {
#endif
			_dmx_slots = slots;
			//zero remainder of buffer
		   for (int n=packetSize+18; n<ARTNET_BUFFER_MAX; n++) {
			  _packet_buffer[n] = 0;
		    }
		  opcode = ARTNET_ART_DMX;
#if defined ( NO_HTP_IS_SINGLE_SENDER )
		}	// matched sender
#endif
	}
	return opcode;
}

void LXArtNet::sendDMX ( UDP* eUDP, IPAddress to_ip ) {
   strcpy((char*)_packet_buffer, "Art-Net");
   _packet_buffer[8] = 0;        //op code lo-hi
   _packet_buffer[9] = 0x50;
   _packet_buffer[10] = 0;
   _packet_buffer[11] = 14;
   if ( _sequence == 0 ) {
     _sequence = 1;
   } else {
     _sequence++;
   }
   _packet_buffer[12] = _sequence;
   _packet_buffer[13] = 0;
   _packet_buffer[14] = _universe;
   _packet_buffer[15] = _net;
   _packet_buffer[16] = _dmx_slots >> 8;
   _packet_buffer[17] = _dmx_slots & 0xFF;
   //assume dmx data has been set

   eUDP->beginPacket(to_ip, ARTNET_PORT);
   eUDP->write(_packet_buffer, 18+_dmx_slots);
   eUDP->endPacket();
}

/*
  sends ArtDMX packet to UDP object's remoteIP if to_ip is not specified
  ( remoteIP is set when parsePacket() is called )
  includes my_ip as address of this node
*/
void LXArtNet::send_art_poll_reply( UDP* eUDP ) {
	_reply_buffer[18]  = _net;
	_reply_buffer[19]  = (_universe >> 4) & 0x0f;
	_reply_buffer[190] = _universe & 0x0f;

  IPAddress a = _broadcast_address;
  if ( a == INADDR_NONE ) {
    a = eUDP->remoteIP();   // reply directly if no broadcast address is supplied
  }
  eUDP->beginPacket(a, ARTNET_PORT);
  eUDP->write(_reply_buffer, ARTNET_REPLY_SIZE);
  eUDP->endPacket();
}

void LXArtNet::send_art_tod ( UDP* wUDP, uint8_t* todata, uint8_t ucount ) {
	if ( ! (_broadcast_address == INADDR_NONE) ) {
		uint8_t _buffer[ARTNET_TOD_PKT_SIZE];
		int i;
		for ( i=0; i < ARTNET_TOD_PKT_SIZE; i++ ) {
			_buffer[i] = 0;
		}
		strcpy((char*)_buffer, "Art-Net");
		_buffer[8] =  0;		// op code lo-hi
		_buffer[9] =  0x81;
		_buffer[10] = 0;		// Art-Net version
		_buffer[11] = 14;
		_buffer[12] = 1;		// RDM version
		_buffer[13] = 1;		// physical port
		//[14-19] spare
		_buffer[20] = 0;		// bind index root device
		_buffer[21] = _net;	//net same as [15] of art-dmx
		if ( ucount == 0 ) {
			_buffer[22] = 1;	// command response 1= TOD not available
		}
		_buffer[23] = _universe;	//port-address same as [14] of art-dmx
		_buffer[24] = 0;			//total UIDs MSB --only single pkt in this implementation
		_buffer[25] = ucount;		//25 total UIDs LSB
		_buffer[26] = 0;			//26 block count (sequence# for multiple packets)
		_buffer[27] = ucount;		//27 UID count
		uint16_t ulen = 6 * ucount;
		for( i=0; i<ulen; i++) {
			_buffer[28+i] = todata[i];
		}

		wUDP->beginPacket(_broadcast_address, ARTNET_PORT);
  		wUDP->write(_buffer, ulen+28);
  		wUDP->endPacket();
	}	// broadcast != NULL
}

void LXArtNet::send_art_rdm ( UDP* wUDP, uint8_t* rdmdata, IPAddress toa ) {
	uint8_t _buffer[ARTNET_RDM_PKT_SIZE];
	int i;
	for ( i=0; i < ARTNET_RDM_PKT_SIZE; i++ ) {
		_buffer[i] = 0;
	}
	strcpy((char*)_buffer, "Art-Net");
	_buffer[8] =  0;		// op code lo-hi
	_buffer[9] =  0x83;
	_buffer[10] = 0;		// Art-Net version
	_buffer[11] = 14;
	_buffer[12] = 1;		// RDM version
	//[13-20] spare
	_buffer[20] = 1;		// bind index root device
	_buffer[21] = _net;		//net same as [15] of art-dmx
	_buffer[22] = 0;		// command response 0= process the packet
	_buffer[23] = _universe;	//port-address same as [14] of art-dmx

	uint16_t rlen = rdmdata[2] + 1;
	for( i=0; i<rlen; i++) {
		_buffer[24+i] = rdmdata[i+1];
	}

	wUDP->beginPacket(toa, ARTNET_PORT);
	wUDP->write(_buffer, rlen+24);
	wUDP->endPacket();
}

void LXArtNet::setArtTodRequestCallback(ArtNetDataRecvCallback callback) {
	_art_tod_req_callback = callback;
}

void LXArtNet::setArtRDMCallback(ArtNetDataRecvCallback callback) {
	_art_rdm_callback = callback;
}

void LXArtNet::setArtCommandCallback(ArtNetDataRecvCallback callback) {
	_art_cmd_callback = callback;
}

uint16_t LXArtNet::parse_header( void ) {
  if ( strcmp((const char*)_packet_buffer, "Art-Net") == 0 ) {
    return _packet_buffer[9] * 256 + _packet_buffer[8];  //opcode lo byte first
  }
  return ARTNET_NOP;
}

/*
  reads an ARTNET_ART_ADDRESS packet
  can set output universe
  can cancel merge which resets address of dmx sender
     (after first ArtDmx packet, only packets from the same sender are accepted
     until a cancel merge command is received)
*/
uint16_t LXArtNet::parse_art_address( UDP* wUDP ) {
   setNetAddress(_packet_buffer[12]);
	//[14] to [31] short name <= 18 bytes
	if ( _packet_buffer[14] != 0 ) {
		strcpy(shortName(), (char*)&_packet_buffer[14]);
	}
	//[32] to [95] long name  <= 64 bytes
	if ( _packet_buffer[32] != 0 ) {
		strcpy(longName(), (char*)&_packet_buffer[32]);
	}
	//[96][97][98][99]                  input universe   ch 1 to 4
	//[100][101][102][103]               output universe   ch 1 to 4
	setUniverseAddress(_packet_buffer[100]);
	//[102][103][104][105]                      subnet   ch 1 to 4
	setSubnetAddress(_packet_buffer[104]);
	//[105]                                   reserved
	uint8_t command = _packet_buffer[106]; // command
	switch ( command ) {
	   case 0x01:	//cancel merge: resets ip address used to identify dmx sender
		   if ( _using_htp ) {
				if ( _dmx_sender != wUDP->remoteIP() ) {
					_dmx_sender =   (uint32_t)0;
					for(int k=0; k<DMX_UNIVERSE_SIZE; k++) {
						_dmx_buffer_a[k] = 0;
					}
				}
				if ( _dmx_sender_b != wUDP->remoteIP() ) {
					_dmx_sender_b = (uint32_t)0;
					for(int k=0; k<DMX_UNIVERSE_SIZE; k++) {
						_dmx_buffer_b[k] = 0;
					}
				}
		   } else {
				_dmx_sender = (uint32_t)0;
				for(int j=18; j<ARTNET_BUFFER_MAX; j++) {
				   _packet_buffer[j] = 0;
				}
		   }
		   break;
	   case 0x90:	//clear buffer
	   		if ( _using_htp ) {
	   			_dmx_sender = (uint32_t)0;
	   			_dmx_sender_b = (uint32_t)0;
				for(int j=0; j<DMX_UNIVERSE_SIZE; j++) {
				   _dmx_buffer_a[j] = 0;
				   _dmx_buffer_b[j] = 0;
				}
	   			_dmx_slots = 512;
	   		} else {
				_dmx_sender = (uint32_t)0;
				for(int j=18; j<ARTNET_BUFFER_MAX; j++) {
				   _packet_buffer[j] = 0;
				}
				_dmx_slots = 512;
			}
	   	return ARTNET_ART_DMX;	// return ARTNET_ART_DMX so function calling readPacket
	   	   						   // knows there has been a change in levels
	   	break;
	}
	return ARTNET_ART_ADDRESS;
}

uint16_t LXArtNet::parse_art_tod_request( UDP* wUDP ) {
	if ( _art_tod_req_callback != NULL ) {
		if ( _packet_buffer[21] == _net ) {
			if ( _packet_buffer[24] == _universe ) {	//array[32] of port-address
				uint8_t type = 0;
				_art_tod_req_callback(&type);	//pointer to uint8_t could be array of other params
				return ARTNET_ART_TOD_REQUEST;
			}
		}
	}
	return ARTNET_NOP;
}

uint16_t LXArtNet::parse_art_tod_control( UDP* wUDP ) {
	if ( _art_tod_req_callback != NULL ) {
		if ( _packet_buffer[21] == _net ) {
			if ( _packet_buffer[23] == _universe ) {
				uint8_t type = 1;
				_art_tod_req_callback(&type);	//pointer to uint8_t could be array of other params
				return ARTNET_ART_TOD_CONTROL;
			}
		}
	}
	return ARTNET_NOP;
}

uint16_t LXArtNet::parse_art_rdm( UDP* wUDP ) {
	if ( _art_rdm_callback != NULL ) {
		if ( _packet_buffer[21] == _net ) {
			if ( _packet_buffer[23] == _universe ) {
				_art_rdm_callback(&_packet_buffer[24]);
				return ARTNET_ART_RDM;
			}
		}
	}
	return ARTNET_NOP;
}

void LXArtNet::parse_art_cmd( UDP* wUDP ) {
	if ( _art_cmd_callback != NULL ) {
		if ( _packet_buffer[12] == 0xFF ) {			// wildcard mfg ID
			if ( _packet_buffer[13] == 0xFF ) {
				_art_cmd_callback(&_packet_buffer[16]);
			}
		}
	}
}

void  LXArtNet::initializePollReply  ( void ) {
	int i;
  for ( i = 0; i < ARTNET_REPLY_SIZE; i++ ) {
    _reply_buffer[i] = 0;
  }
  strcpy((char*)_reply_buffer, "Art-Net");
  _reply_buffer[7] = 0;
  _reply_buffer[8] = 0;        // op code lo-hi
  _reply_buffer[9] = 0x21;
  _reply_buffer[10] = ((uint32_t)_my_address) & 0xff;      //ip address
  _reply_buffer[11] = ((uint32_t)_my_address) >> 8;
  _reply_buffer[12] = ((uint32_t)_my_address) >> 16;
  _reply_buffer[13] = ((uint32_t)_my_address) >> 24;
  _reply_buffer[14] = 0x36;    // port lo first always 0x1936
  _reply_buffer[15] = 0x19;
  _reply_buffer[16] = 0;       // firmware hi-lo
  _reply_buffer[17] = 0;
  _reply_buffer[18] = 0;       // subnet hi-lo
  _reply_buffer[19] = 0;
  _reply_buffer[20] = 0;       // oem hi-lo 0x1250
  _reply_buffer[21] = 0;
  _reply_buffer[22] = 0;       // ubea
  _reply_buffer[23] = 0;       // status
  _reply_buffer[24] = 0x6C;    //     ESTA Mfg Code
  _reply_buffer[25] = 0x78;
  strcpy((char*)&_reply_buffer[26], "ArduinoDMX");
  strcpy((char*)&_reply_buffer[44], "ArduinoDMX");
  _reply_buffer[173] = 1;    // number of ports
  _reply_buffer[174] = 0x80;  // can output from network
  _reply_buffer[182] = 0x80;  //  good output... change if error
  _reply_buffer[190] = _universe;
}


text:
package main

import (
	"log"

	cqlquery "github.com/flikmsg/go-cql-query-builder"
)

func main() {
	if _, err := cqlquery.Connect([]string{"127.0.0.1"}, "test_keyspace"); err != nil {
		log.Fatal(err)
	}

	query := cqlquery.Select("users_by_username", []string{"user_id", "username"}, map[string]interface{}{
		"username": "tyler",
	})

	results := query.Iter()
	defer results.Close()

	m := map[string]interface{}{}
	if results.MapScan(m) {
		log.Printf("User ID: %s, Username: %s", m["user_id"], m["username"])
	} else {
		log.Println("No user found.")
	}
}

repository: flikmsg/go-cql-query-builder

repo_name: flikmsg/go-cql-query-builder