double vs_term_freqency(vector *v, t_uuid dimensionid){ int max,i,val; double term_total, document_total; dimension *dim,*dims; t_uuid v_dimensionid; vs_value value; dim = vs_getvalue(v,dimensionid); term_total=0; if(dim!=NULL){ value = dim->value; term_total = value.floatvalue; } document_total = 0; max = v->dimensioncount; i=0; dims = v->dimensions; while (i<max){ val = (int)dims + (int)(i * sizeof(dimension)); dim = (dimension *)(val); v_dimensionid = dim->dimensionid; value = dim->value; if(!IsEqualGuid(dimensionid,v_dimensionid)){ document_total+=value.floatvalue; } i++; } if(document_total==0){ return 0; } return (term_total / document_total ); }
vs_cursor *vsc_normalize (vs_cursor *source){ vs_cursor *normalized; vs_rowset *rowset; dimension *dims,*dim ; vector *v, *view_v, *compare, *final; t_uuid id; long max,i,dimval,c; normalized = vsc_createcursor(); printf( "Normalize: %ld vectors\r\n",source->count); vsc_reset (source) ; // view = vsc_create_view(source); printf("Normalizing: %ld vectors\r\n",source->count); c=0; while ( !vsc_eof (source) ){ c++; v = vsc_readnext(source); // printf(" Vector %ld of %ld : has %ld ",c,source->count, v->dimensioncount); compare = vs_createvector(NullGuid(),0); max = v->dimensioncount; dims= v->dimensions; rowset = vsr_createrowset(source,v); vsr_reset(rowset); while (!vsr_eof (rowset)){ view_v = vsr_readnext(rowset); if (!IsEqualGuid(v->vectorid,view_v->vectorid)){ for (i=0;i<max;i++){ dimval = (long)dims + (long)(i * sizeof(dimension)); dim = (dimension *)(dimval); id = dim->dimensionid; if (vsc_normalize_hasdimension(view_v,id)){ vsc_normalize_incriment_dimension(compare,id); } } } } //now we have compare, holding some dimensions with values>1 matching our vector. //we need to clean out any dimensions in our vector that don't have corresponding values final = vsc_normalize_vector(v,compare); // printf(" ending at %ld \r\n",compare->dimensioncount); if(final!=NULL){ vsc_rawloadvector(normalized,final); } vsr_destroyrowset(&rowset); vs_destroyvector(&compare); }
/* * D3DAppIDDEnumCallback * Callback function used during enumeration of DirectDraw drivers. * During enumeration, if a 3D capable hardware device is found, it is * created and *(LPDIRECTDRAW*)lpContext is set to it. Otherwise, does * nothing. */ BOOL FAR PASCAL D3DAppIDDEnumCallback(GUID FAR* lpGUID, LPSTR lpDriverDesc, LPSTR lpDriverName, LPVOID lpContext) { LPDIRECTDRAW lpDD; DDCAPS DriverCaps, HELCaps; #ifdef FINAL_RELEASE BOOL ThisOne = FALSE; #endif /* * A NULL GUID* indicates the DirectDraw HEL which we are not interested * in at the moment. */ // if (lpGUID) { /* * Create the DirectDraw device using this driver. If it fails, * just move on to the next driver. */ if (FAILED(DirectDrawCreate(lpGUID, &lpDD, NULL))) { return DDENUMRET_OK; } /* * Get the capabilities of this DirectDraw driver. If it fails, * just move on to the next driver. */ memset(&DriverCaps, 0, sizeof(DDCAPS)); DriverCaps.dwSize = sizeof(DDCAPS); memset(&HELCaps, 0, sizeof(DDCAPS)); HELCaps.dwSize = sizeof(DDCAPS); if (FAILED(lpDD->lpVtbl->GetCaps(lpDD, &DriverCaps, &HELCaps))) { lpDD->lpVtbl->Release(lpDD); return DDENUMRET_OK; } #ifdef FINAL_RELEASE if (DriverCaps.dwCaps & DDCAPS_3D ) { if( !lpGUID && !DeviceGuidPnt) { ThisOne = TRUE; } if( DeviceGuidPnt && lpGUID ) { if( IsEqualGuid( lpGUID, &DeviceGuid) ) { ThisOne = TRUE; } } if( ThisOne ) { /* * We have found a 3d hardware device. Return the DD object * and stop enumeration. */ d3dappi.bIsPrimary = FALSE; *(LPDIRECTDRAW*)lpContext = lpDD; return DDENUMRET_CANCEL; } } #else if (DriverCaps.dwCaps & DDCAPS_3D ) { if( ddcount3d++ == ddchosen3d ) { /* * We have found a 3d hardware device. Return the DD object * and stop enumeration. */ #ifdef ORIGINAL d3dappi.bIsPrimary = FALSE; #else d3dappi.bIsPrimary = TRUE; // This is no longer a DD limitation. #endif *(LPDIRECTDRAW*)lpContext = lpDD; return DDENUMRET_CANCEL; } } #endif lpDD->lpVtbl->Release(lpDD); } return DDENUMRET_OK; }
/* objects can be buttons, axis, sliders etc... */ bool CALLBACK DIEnumDeviceObjectsProc( LPCDIDEVICEOBJECTINSTANCE lpddoi, /* the object instance */ LPVOID pvRef) /* pointer to void we passed in from calling block */ { int joysticknum, axis, dir; /* you have to use these or you get a warning */ GUID AxisGUID[MAX_JOYSTICK_AXIS - 1]; GUID ButtonGUID = GUID_Button; GUID POVGUID = GUID_POV; GUID CompareGUID = lpddoi->guidType; /* pointer to the current object GUID type */ /* pvRef is a pointer to a passed in object from our calling code */ /* here we passed in the current joystick number */ joysticknum = *((int *)(pvRef)); /* types of axis's we have to support */ AxisGUID[0] = GUID_XAxis; AxisGUID[1] = GUID_YAxis; AxisGUID[2] = GUID_ZAxis; AxisGUID[3] = GUID_RxAxis; AxisGUID[4] = GUID_RyAxis; AxisGUID[5] = GUID_RzAxis; AxisGUID[6] = GUID_Slider; // This holds an array of up to 2 sliders /* loop over the AxisGUID[] Array */ /* find out if current object is one of type in AxisGUID[] */ for (axis = 0; axis < MAX_JOYSTICK_AXIS - 1; axis++) { /* if the object is not equal to AxisGUID[axis] then continue */ if ( ! IsEqualGuid( &AxisGUID[axis], &CompareGUID )) continue; /* allocate the memory */ JoystickInfo[joysticknum].Axis[axis].name = (char*) malloc (MAX_JOYNAME+1); /* assign all /0's to the stack */ memset (JoystickInfo[joysticknum].Axis[axis].name, 0, (MAX_JOYNAME+1)); /* if object provides a name */ if (lpddoi->tszName && *lpddoi->tszName) /* use the special name */ strncpy( JoystickInfo[joysticknum].Axis[axis].name, lpddoi->tszName, MAX_JOYNAME ); else /* use generic name */ snprintf( JoystickInfo[joysticknum].Axis[axis].name, MAX_JOYNAME, "Axis %d", axis ); /* this current axis exists */ JoystickInfo[joysticknum].Axis[axis].exists = true; /* up the count */ /* NumAxis==1 means JoystickInfo[0] is set */ JoystickInfo[joysticknum].NumAxis++; /* were done we found out what object we were dealing with */ return DIENUM_CONTINUE; } /* if the object is a button */ if (IsEqualGuid( &ButtonGUID, &CompareGUID )) { /* allocate the memory */ JoystickInfo[joysticknum].Button[ JoystickInfo[joysticknum].NumButtons ].name = (char *) malloc (MAX_JOYNAME+1); /* assign all /0's to the stack */ memset ( JoystickInfo[joysticknum].Button[JoystickInfo[joysticknum].NumButtons].name, 0, (MAX_JOYNAME+1) ); /* if object provides a name */ if (lpddoi->tszName && *lpddoi->tszName) /* use the special name */ strncpy( JoystickInfo[joysticknum].Button[JoystickInfo[joysticknum].NumButtons].name, lpddoi->tszName, MAX_JOYNAME ); else /* use generic name */ snprintf( JoystickInfo[joysticknum].Button[ JoystickInfo[joysticknum].NumButtons ].name, MAX_JOYNAME, "Button %d", JoystickInfo[joysticknum].NumButtons ); /* up the count */ JoystickInfo[joysticknum].NumButtons++; /* were done with this object go to next one */ return DIENUM_CONTINUE; } /* if the object is a POV aka Hat Switch */ if (IsEqualGuid( &POVGUID, &CompareGUID )) { /* allocate the memory */ JoystickInfo[joysticknum].POV[JoystickInfo[joysticknum].NumPOVs].name = (char *) malloc (MAX_JOYNAME+1); /* assign all /0's to the stack */ memset ( JoystickInfo[joysticknum].POV[JoystickInfo[joysticknum].NumPOVs].name, 0, (MAX_JOYNAME+1) ); /* if object provides a name */ if (lpddoi->tszName && *lpddoi->tszName) /* use the special name */ strncpy( JoystickInfo[joysticknum].POV[JoystickInfo[joysticknum].NumPOVs].name, lpddoi->tszName, MAX_JOYNAME ); else /* use generic name */ snprintf( JoystickInfo[joysticknum].POV[JoystickInfo[joysticknum].NumPOVs].name, MAX_JOYNAME, "Hat %d", JoystickInfo[joysticknum].NumPOVs ); /* set the name of the direction */ for ( dir = 0; dir < MAX_POV_DIRECTIONS; dir++ ) { /* allocate the memory */ JoystickInfo[joysticknum].POV[JoystickInfo[joysticknum].NumPOVs].dirname[ dir ] = (char *) malloc (MAX_JOYNAME+1); /* assign all /0's to the stack */ memset ( JoystickInfo[joysticknum].POV[JoystickInfo[joysticknum].NumPOVs].dirname[ dir ], 0, (MAX_JOYNAME+1) ); /* use generic name */ snprintf( JoystickInfo[joysticknum].POV[JoystickInfo[joysticknum].NumPOVs].dirname[ dir ], MAX_JOYNAME, "%s %d", JoystickInfo[joysticknum].POV[JoystickInfo[joysticknum].NumPOVs].name, JoystickInfo[joysticknum].NumPOVs ); } /* up the count */ JoystickInfo[joysticknum].NumPOVs++; /* were done with this object go to next */ return DIENUM_CONTINUE; } /* default we couldn't find out what this object is so continue */ return DIENUM_CONTINUE; }