📄 lib_components.cpp
字号:
return 0;
PyCATCH_1
}
string convertToString(const PDomainContingency &cont)
{
string res=string("{");
const_PITERATE(TDomainContingency, di, cont) {
if (di!=cont->begin()) res+=", ";
res += (*di)->outerVariable->name+": "+convertToString(*di);
}
return res+"}";
}
PyObject *DomainContingency_normalize(PyObject *self, PyObject *) PYARGS(0, "() -> None")
{ PyTRY
if (!PyOrange_AS_Orange(self))
PYERROR(PyExc_SystemError, "NULL contingency matrix", PYNULL);
SELF_AS(TDomainContingency).normalize();
RETURN_NONE
PyCATCH
}
/* ************ DISTANCE ************ */
#include "distance.hpp"
#include "distance_dtw.hpp"
ABSTRACT(ExamplesDistance_Normalized, ExamplesDistance)
C_NAMED(ExamplesDistance_Hamming, ExamplesDistance, "()")
C_NAMED(ExamplesDistance_Maximal, ExamplesDistance_Normalized, "()")
C_NAMED(ExamplesDistance_Manhattan, ExamplesDistance_Normalized, "()")
C_NAMED(ExamplesDistance_Euclidean, ExamplesDistance_Normalized, "()")
C_NAMED(ExamplesDistance_Relief, ExamplesDistance, "()")
C_NAMED(ExamplesDistance_DTW, ExamplesDistance_Normalized, "()")
C_CALL(ExamplesDistanceConstructor_Hamming, ExamplesDistanceConstructor, "([examples, weightID][, DomainDistributions][, DomainBasicAttrStat]) -/-> ExamplesDistance_Hamming")
C_CALL(ExamplesDistanceConstructor_Maximal, ExamplesDistanceConstructor, "([examples, weightID][, DomainDistributions][, DomainBasicAttrStat]) -/-> ExamplesDistance_Maximal")
C_CALL(ExamplesDistanceConstructor_Manhattan, ExamplesDistanceConstructor, "([examples, weightID][, DomainDistributions][, DomainBasicAttrStat]) -/-> ExamplesDistance_Manhattan")
C_CALL(ExamplesDistanceConstructor_Euclidean, ExamplesDistanceConstructor, "([examples, weightID][, DomainDistributions][, DomainBasicAttrStat]) -/-> ExamplesDistance_Euclidean")
C_CALL(ExamplesDistanceConstructor_Relief, ExamplesDistanceConstructor, "([examples, weightID][, DomainDistributions][, DomainBasicAttrStat]) -/-> ExamplesDistance_Relief")
C_CALL(ExamplesDistanceConstructor_DTW, ExamplesDistanceConstructor, "([examples, weightID][, DomainDistributions][, DomainBasicAttrStat]) -/-> ExamplesDistance_DTW")
PyObject *ExamplesDistanceConstructor_new(PyTypeObject *type, PyObject *args, PyObject *keywords) BASED_ON(Orange, "<abstract>")
{ if (type == (PyTypeObject *)&PyOrExamplesDistanceConstructor_Type)
return setCallbackFunction(WrapNewOrange(mlnew TExamplesDistanceConstructor_Python(), type), args);
else
return WrapNewOrange(mlnew TExamplesDistanceConstructor_Python(), type);
}
PyObject *ExamplesDistanceConstructor__reduce__(PyObject *self)
{
return callbackReduce(self, PyOrExamplesDistanceConstructor_Type);
}
PyObject *ExamplesDistance_new(PyTypeObject *type, PyObject *args, PyObject *keywords) BASED_ON(Orange, "<abstract>")
{ if (type == (PyTypeObject *)&PyOrExamplesDistance_Type)
return setCallbackFunction(WrapNewOrange(mlnew TExamplesDistance_Python(), type), args);
else
return WrapNewOrange(mlnew TExamplesDistance_Python(), type);
}
PyObject *ExamplesDistance__reduce__(PyObject *self)
{
return callbackReduce(self, PyOrExamplesDistance_Type);
}
PyObject *ExamplesDistanceConstructor_call(PyObject *self, PyObject *uargs, PyObject *keywords) PYDOC("([examples, weightID][, DomainDistributions][, DomainBasicAttrStat]) -/-> ExamplesDistance")
{ PyTRY
if (PyOrange_OrangeBaseClass(self->ob_type) == &PyOrExamplesDistanceConstructor_Type) {
PyErr_Format(PyExc_SystemError, "ExamplesDistanceConstructor.call called for '%s': this may lead to stack overflow", self->ob_type->tp_name);
return PYNULL;
}
NO_KEYWORDS
PyObject *args[4] = {PYNULL, PYNULL, PYNULL, PYNULL};
PExampleGenerator gen;
int weightID = 0;
PDomainDistributions dist;
PDomainBasicAttrStat bstat;
if (!PyArg_UnpackTuple(uargs, "ExamplesDistanceConstructor.call", 0, 4, args+0, args+1, args+2, args+3))
return PYNULL;
PyObject **argp = args, **argc = args;
for (int i=0; i<=3; i++, argp++)
if (*argp)
*argc++ = *argp;
for(argp = args; argp!=argc; argp++) {
if (PyOrDomainDistributions_Check(*argp))
if (dist)
PYERROR(PyExc_TypeError, "ExamplesDistanceConstructor.__call__: invalid arguments (DomainDistribution given twice)", PYNULL)
else
dist = PyOrange_AsDomainDistributions(*argp);
else if (PyOrDomainBasicAttrStat_Check(*argp))
if (bstat)
PYERROR(PyExc_TypeError, "ExamplesDistanceConstructor.__call__: invalid arguments (DomainBasicAttrStat given twice)", PYNULL)
else
bstat = PyOrange_AsDomainBasicAttrStat(*argp);
else {
PExampleGenerator gen2 = exampleGenFromParsedArgs(*argp);
if (!gen2)
PYERROR(PyExc_TypeError, "ExamplesDistanceConstructor.__call__: invalid arguments", PYNULL)
else if (gen)
PYERROR(PyExc_TypeError, "ExamplesDistanceConstructor.__call__: invalid arguments (examples given twice)", PYNULL)
else {
gen = gen2;
if (argp+1 != argc) {
argp++;
if (!weightFromArg_byDomain(*argp, gen->domain, weightID))
return PYNULL;
}
}
}
}
return WrapOrange(SELF_AS(TExamplesDistanceConstructor).call(gen, weightID, dist, bstat));
PyCATCH
}
PyObject *ExamplesDistance_Normalized_attributeDistances(PyObject *self, PyObject *args) PYARGS(METH_VARARGS, "(example1, example2) -> [by-attribute distances as floats]")
{ PyTRY
TExample *ex1, *ex2;
if (!PyArg_ParseTuple(args, "O&O&:ExamplesDistance_Normalized.attributeDistances", ptr_Example, &ex1, ptr_Example, &ex2))
PYERROR(PyExc_TypeError, "attribute error (two examples expected)", PYNULL);
vector<float> difs;
SELF_AS(TExamplesDistance_Normalized).getDifs(*ex1, *ex2, difs);
PyObject *l = PyList_New(difs.size());
for(int i = 0, e = difs.size(); i<e; e++)
PyList_SetItem(l, i, PyFloat_FromDouble(difs[i]));
return l;
PyCATCH
}
PyObject *ExamplesDistance_call(PyObject *self, PyObject *args, PyObject *keywords) PYDOC("(example1, example2) -> float")
{
PyTRY
NO_KEYWORDS
if (PyOrange_OrangeBaseClass(self->ob_type) == &PyOrExamplesDistance_Type) {
PyErr_Format(PyExc_SystemError, "ExamplesDistance.call called for '%s': this may lead to stack overflow", self->ob_type->tp_name);
return PYNULL;
}
TExample *ex1, *ex2;
if (!PyArg_ParseTuple(args, "O&O&:ExamplesDistance_Normalized.__call__", ptr_Example, &ex1, ptr_Example, &ex2))
PYERROR(PyExc_TypeError, "attribute error (two examples expected)", PYNULL);
return PyFloat_FromDouble((double)(SELF_AS(TExamplesDistance)(*ex1, *ex2)));
PyCATCH
}
PYCLASSCONSTANT_INT(ExamplesDistance_DTW, Euclidean, TExamplesDistance_DTW::DTW_EUCLIDEAN)
PYCLASSCONSTANT_INT(ExamplesDistance_DTW, Derivative, TExamplesDistance_DTW::DTW_DERIVATIVE)
bool convertFromPython(PyObject *pyobj, TAlignment &align)
{
return PyArg_ParseTuple(pyobj, "ii:convertFromPython(Alignment)", &align.i, &align.j) != 0;
}
PyObject *convertToPython(const TAlignment &align)
{
return Py_BuildValue("ii", align.i, align.j);
}
PyObject *ExamplesDistance_DTW_alignment(PyObject *self, PyObject *args) PYARGS(METH_VARARGS, "(example1, example2) -> (distance, path)")
{
PyTRY
TExample *ex1, *ex2;
if (!PyArg_ParseTuple(args, "O&O&:ExamplesDistance_DTW.attributeDistances", ptr_Example, &ex1, ptr_Example, &ex2))
PYERROR(PyExc_TypeError, "attribute error (two examples expected)", PYNULL);
PWarpPath warpPath;
float distance = SELF_AS(TExamplesDistance_DTW)(*ex1, *ex2, warpPath);
return Py_BuildValue("fO", distance, WrapOrange(warpPath));
PyCATCH
}
/* ************ FINDNEAREST ************ */
#include "nearest.hpp"
ABSTRACT(FindNearest, Orange)
C_NAMED(FindNearest_BruteForce, FindNearest, "([distance=, distanceID=, includeSame=])")
ABSTRACT(FindNearestConstructor, Orange)
C_CALL(FindNearestConstructor_BruteForce, FindNearestConstructor, "([examples[, weightID[, distanceID]], distanceConstructor=, includeSame=]) -/-> FindNearest")
PyObject *FindNearestConstructor_call(PyObject *self, PyObject *args, PyObject *keywords) PYDOC("(examples[, weightID[, distanceID]]) -> FindNearest")
{
PyTRY
NO_KEYWORDS
PExampleGenerator egen;
int weightID = 0;
int distanceID = 0;
PyObject *pydistanceID = PYNULL;
if ( !PyArg_ParseTuple(args, "O&|O&O:FindNearestConstructor.__call__", pt_ExampleGenerator, &egen, pt_weightByGen(egen), &weightID, &pydistanceID)
|| !weightFromArg_byDomain(pydistanceID, egen->domain, distanceID))
return PYNULL;
return WrapOrange(SELF_AS(TFindNearestConstructor).call(egen, weightID, distanceID));
PyCATCH
}
PyObject *FindNearest_call(PyObject *self, PyObject *args, PyObject *keywords) PYDOC("(example, k) -> ExampleTable")
{
PyTRY
NO_KEYWORDS
float k;
TExample *example;
int needsClass = 0;
// Both forms are allowed for compatibility with older versions
if (!PyArg_ParseTuple(args, "fO&|i", &k, ptr_Example, &example, &needsClass)) {
PyErr_Clear();
if (!PyArg_ParseTuple(args, "O&f|i", ptr_Example, &example, &k, &needsClass))
PYERROR(PyExc_TypeError, "attribute error (number and example, and an optional flag for class expected)", PYNULL);
}
return WrapOrange(SELF_AS(TFindNearest).call(*example, k, needsClass != 0));
PyCATCH
}
/* ************ FILTERS ************ */
#include "filter.hpp"
ABSTRACT(ValueFilter, Orange)
C_NAMED(ValueFilter_discrete, ValueFilter, "([position=, oper=, values=, acceptSpecial=])")
C_NAMED(ValueFilter_continuous, ValueFilter, "([position=, oper=, min=, max=, acceptSpecial=])")
C_NAMED(ValueFilter_string, ValueFilter, "([position=, oper=, min=, max=])");
C_NAMED(ValueFilter_stringList, ValueFilter, "([position=, oper=, values=])");
PYCLASSCONSTANT_INT(ValueFilter, Equal, int(TValueFilter::Equal))
PYCLASSCONSTANT_INT(ValueFilter, NotEqual, int(TValueFilter::NotEqual))
PYCLASSCONSTANT_INT(ValueFilter, Less, int(TValueFilter::Less))
PYCLASSCONSTANT_INT(ValueFilter, LessEqual, int(TValueFilter::LessEqual))
PYCLASSCONSTANT_INT(ValueFilter, Greater, int(TValueFilter::Greater))
PYCLASSCONSTANT_INT(ValueFilter, GreaterEqual, int(TValueFilter::GreaterEqual))
PYCLASSCONSTANT_INT(ValueFilter, Between, int(TValueFilter::Between))
PYCLASSCONSTANT_INT(ValueFilter, Outside, int(TValueFilter::Outside))
PYCLASSCONSTANT_INT(ValueFilter, Contains, int(TValueFilter::Contains))
PYCLASSCONSTANT_INT(ValueFilter, NotContains, int(TValueFilter::NotContains))
PYCLASSCONSTANT_INT(ValueFilter, BeginsWith, int(TValueFilter::BeginsWith))
PYCLASSCONSTANT_INT(ValueFilter, EndsWith, int(TValueFilter::EndsWith))
PYCLASSCONSTANT_INT(Filter_values, Equal, int(TValueFilter::Equal))
PYCLASSCONSTANT_INT(Filter_values, NotEqual, int(TValueFilter::NotEqual))
PYCLASSCONSTANT_INT(Filter_values, Less, int(TValueFilter::Less))
PYCLASSCONSTANT_INT(Filter_values, LessEqual, int(TValueFilter::LessEqual))
PYCLASSCONSTANT_INT(Filter_values, Greater, int(TValueFilter::Greater))
PYCLASSCONSTANT_INT(Filter_values, GreaterEqual, int(TValueFilter::GreaterEqual))
PYCLASSCONSTANT_INT(Filter_values, Between, int(TValueFilter::Between))
PYCLASSCONSTANT_INT(Filter_values, Outside, int(TValueFilter::Outside))
PYCLASSCONSTANT_INT(Filter_values, Contains, int(TValueFilter::Contains))
PYCLASSCONSTANT_INT(Filter_values, NotContains, int(TValueFilter::NotContains))
PYCLASSCONSTANT_INT(Filter_values, BeginsWith, int(TValueFilter::BeginsWith))
PYCLASSCONSTANT_INT(Filter_values, EndsWith, int(TValueFilter::EndsWith))
C_CALL(Filter_random, Filter, "([examples], [negate=..., p=...]) -/-> ExampleTable")
C_CALL(Filter_hasSpecial, Filter, "([examples], [negate=..., domain=...]) -/-> ExampleTable")
C_CALL(Filter_isDefined, Filter, "([examples], [negate=..., domain=..., check=]) -/-> ExampleTable")
C_CALL(Filter_hasMeta, Filter, "([examples], [id=...]) -/-> ExampleTable")
C_CALL(Filter_hasClassValue, Filter, "([examples], [negate=..., domain=...]) -/-> ExampleTable")
C_CALL(Filter_sameValue, Filter, "([examples], [negate=..., domain=..., position=<int>, value=...]) -/-> ExampleTable")
C_CALL(Filter_values, Filter, "([examples], [negate=..., domain=..., values=<see the manual>) -/-> ExampleTable")
PValueFilterList PValueFilterList_FromArguments(PyObject *arg) { return ListOfWrappedMethods<PValueFilterList, TValueFilterList, PValueFilter, &PyOrValueFilter_Type>::P_FromArguments(arg); }
PyObject *ValueFilterList_FromArguments(PyTypeObject *type, PyObject *arg) { return ListOfWrappedMethods<PValueFilterList, TValueFilterList, PValueFilter, &PyOrValueFilter_Type>::_FromArguments(type, arg); }
PyObject *ValueFilterList_new(PyTypeObject *type, PyObject *arg, PyObject *kwds) BASED_ON(Orange, "(<list of ValueFilter>)") ALLOWS_EMPTY { return ListOfWrappedMethods<PValueFilterList, TValueFilterList, PValueFilter, &PyOrValueFilter_Type>::_new(type, arg, kwds); }
PyObject *ValueFilterList_getitem_sq(TPyOrange *self, int index) { return ListOfWrappedMethods<PValueFilterList, TValueFilterList, PValueFilter, &PyOrValueFilter_Type>::_getitem(self, index); }
int ValueFilterList_setitem_sq(TPyOrange *self, int index, PyObject *item) { return ListOfWrappedMethods<PValueFilterList, TValueFilterList, PValueFilter, &PyOrValueFilter_Type>::_setitem(self, index, item); }
PyObject *ValueFilterList_getslice(TPyOrange *self, int start, int stop) { return ListOfWrappedMethods<PValueFilterList, TValueFilterList, PValueFilter, &PyOrValueFilter_Type>::_getslice(self, start, stop); }
int ValueFilterList_setslice(TPyOrange *self, int start, int stop, PyObject *item) { return ListOfWrappedMethods<PValueFilterList, TValueFilterList, PValueFilter, &PyOrValueFilter_Type>::_setslice(self, start, stop, item); }
int ValueFilterList_len_sq(TPyOrange *self) { return ListOfWrappedMethods<PValueFilterList, TValueFilterList, PValueFilter, &PyOrValueFilter_Type>::_len(self); }
PyObject *ValueFilterList_richcmp(TPyOrange *self, PyObject *object, int op) { return ListOfWrappedMethods<PValueFilterList, TValueFilterList, PValueFilter, &PyOrValueFilter_Type>::_richcmp(self, object, op); }
PyObject *ValueFilterList_concat(TPyOrange *self, PyObject *obj) { return ListOfWrappedMethods<PValueFilterList, TValueFilterList, PValueFilter, &PyOrValueFilter_Type>::_concat(self, obj); }
PyObject *ValueFilterList_repeat(TPyOrange *self, int times) { return ListOfWrappedMethods<PValueFilterList, TValueFilterList, PValueFilter, &PyOrValueFilter_Type>::_repeat(self, times); }
PyObject *ValueFilterList_str(TPyOrange *self) { return ListOfWrappedMethods<PValueFilterList, TValueFilterList, PValueFilter, &PyOrValueFilter_Type>::_str(self); }
PyObject *ValueFilterList_repr(TPyOrange *self) { return ListOfWrappedMethods<PValueFilterList, TValueFilterList, PValueFilter, &PyOrValueFilter_Type>::_str(self); }
int ValueFilterList_contains(TPyOrange *self, PyObject *obj) { return ListOfWrappedMethods<PValueFilterList, TValueFilterList, PValueFilter, &PyOrValueFilter_Type>::_contains(self, obj); }
PyObject *ValueFilterList_append(TPyOrange *self, PyObject *item) PYARGS(METH_O, "(ValueFilter) -> None") { return ListOfWrappedMethods<PValueFilterList, TValueFilterList, PValueFilter, &PyOrValueFilter_Type>::_append(self, item); }
PyObject *ValueFilterList_extend(TPyOrange *self, PyObject *obj) PYARGS(METH_O, "(sequence) -> None") { return ListOfWrappedMethods<PValueFilterList, TValueFilterList, PValueFilter, &PyOrValueFilter_Type>::_extend(self, obj); }
PyObject *ValueFilterList_count(TPyOrange *self, PyObject *obj) PYARGS(METH_O, "(ValueFilter) -> int") { return ListOfWrappedMethods<PValueFilterList, TValueFilterList, PValueFilter, &PyOrValueFilter_Type>::_count(self, obj); }
PyObject *ValueFilterList_filter(TPyOrange *self, PyObject *args) PYARGS(METH_VARARGS, "([filter-function]) -> ValueFilterList") { return ListOfWrappedMethods<PValueFilterList, TValueFilterList, PValueFilter, &PyOrValueFilter_Type>::_filter(self, args); }
PyObject *ValueFilterList_index(TPyOrange *self, PyObject *obj) PYARGS(METH_O, "(ValueFilter) -> int") { return ListOfWrappedMethods<PValueFilterList, TValueFilterList, PValueFilter, &PyOrValueFilter_Type>::_index(self, obj); }
PyObject *ValueFilterList_insert(TPyOrange *self, PyObject *args) PYARGS(METH_VARARGS, "(index, item) -> None") { return ListOfWrappedMethods<PValueFilterList, TValueFilterList, PValueFilter, &PyOrValueFilter_Type>::_insert(self, args
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -